I have a list of menu items in my sidebar and I want to hide some of them with a token. I have figured out how to make a place to input the token and set the condition to show the menu item, but I am missing something in the server side and I can't quite figure it out. Whenever I enter the token it authenticates but it doesn't show me the conditional menu item.
This is the code:
#Define UI --------------------
ui <- dashboardPage(
dashboardHeader(title= "Health Portal"),
titleWidth = 400),
dashboardSidebar(id = "Directory",
sidebarMenu(
menuItem("Home", tabName = "HME"),
conditionalPanel(
condition = "input.token === 'token1'",
menuItem("Data", tabName = "surv")),
menuItem("Health & Prevention", tabName = "SHP"),
menuItem("Local Health Jurisdictions", tabName = "LHJs",
menuItem("Outbreak", tabName = "Outbreak"),
textInput("access_token", "Access Token:"),
actionButton("authenticate", "Authenticate")
)),
#I have a few more menu items but they are not conditional or anything. I then have page contents, but I don't think that is relevant to the issue.
#Define Server Logic ----
server <- function(input, output, session){
access_tokens <- c("token1")
observeEvent(input$authenticate, {
if(input$access_token %in% access_tokens) {
updateTextInput(session, "access_token", value = "")
updateActionButton(session, "authenticate", label = "Authenticated", disabled = TRUE)
updateCheckboxInput(session, "token", value = input$access_token)
} else {
showModal(modalDialog(
title = "Authentication Failed",
"Invalid access token. Please try again.",
easyClose = TRUE
))
}
})
}
#Deploy App ----
shinyApp(ui = ui, server = server)`
I am just missing something, I think in the server logic. But I can't quite figure it out.