My code is not working as intended. Let me describe a scenario that demonstrates the issue.
A user selects "Action 1" on the 1st tab. Then he/she selects "Choice 1" on the 2nd tab. "Select a node" and "Select a variable" are shown. ---> THIS IS INTENDED.
Same user goes back to the 1st tab and selects "Action 2." When he/she goes to the 2nd tab, he/she selects "Choice 3." Now, "Select a node" and "Select a variable" are still shown. --- > THIS IS NOT CORRECT. They should only appear if a user selects "Choice 1" or "Choice 2."
So, my Shiny app seems to remember the previous selection. Any idea how I can update my codes so it works as intended? Thanks!
server.R:
function(input, output, session) {
# Update SelectInput
observe({
if (input$action=="1") {
updateSelectInput(session, "selectnode", choices = "Total")
} else {
updateSelectInput(session, "selectnode", choices = c('Node 1', 'Node 2', 'Node 3'))
}
})
# Update SelectInput for selectvar
observe({
updateSelectInput(session, "selectvar", choices = c('A','B','C'))
})
observeEvent(input$act_next, {
updateTabsetPanel(session, "allResults", 'structure')
})
}
ui.R:
fluidPage(theme = shinytheme("spacelab"),
navbarPage("Structure", id = "allResults",
tabPanel(value='action', title='User Actions',
verticalLayout(
h4("Select an action"),
radioButtons("action", label = "",
choices = list("Action 1" = 1,
"Action 2" = 2),
selected = 1),
br(),
actionButton("act_next", "Next!")
)
),
tabPanel(value='structure', title='Main',
verticalLayout(
conditionalPanel(
condition = ("input.action==1"),
selectInput("dd_options", label = "Select one option",
choices = c(
"Choice 1" = 1,
"Choice 2" = 2),
selected = 1)
),
conditionalPanel(
condition = ("input.action==2"),
selectInput("dd_options", label = "Select one option",
choices = c(
"Choice 1" = 1,
"Choice 2" = 2,
"Choice 3" = 3),
selected = 3)
),
br(),
conditionalPanel(
condition = ("input.dd_options == 1 || input.dd_options == 2"),
selectInput("selectnode", label = "Select a node", choices = ""),
br()
),
conditionalPanel(
condition = ("input.dd_options == 1 || input.dd_options == 2" ),
selectInput("selectvar", label = "Select a variable", choices = ""),
br()
)
)
)))