RustyStatistician RustyStatistician - 1 year ago 208
R Question

Conditional Panel in Shiny doesn't update variables

I am trying to use a conditional panel in R Shiny but am running into issues with values not being assigned. Here is a snippet of my code:

conditionalPanel(condition="input['input.type']=='Use Example Data'",
textInput("Label", "Enter the label:", "A"),
conditionalPanel(condition="input['input.type']=='Upload Data'",
textInput("Label", "Enter the label:", "B"),

Now, with this code, what I was expecting to happen is if the user selects "Use Example Data" then the default value would be A (which it is), but if the user toggles to "Upload Data" then the default values is still A and not B as I would have expected. It seems only the first conditional panel stores the values since they have the same name?

A second question, when the user toggles between "Use Example Data" and "Upload Data" the conditional panel does change, but if I replace the value of A with, say, C and then toggle back and forth, the value of C will always be there instead of being reset to A. Is there a simple fix for this?

Answer Source

Is this what you want?

rm(list = ls())

ui <- dashboardPage(
    selectInput("type", "Type:",c("Use Example Data","Upload Data"))),
server <- function(input, output) {
  output$myui <- renderUI({
    if(input$type == "Upload Data"){
      textInput("Label", "Enter the label:", "B")
      textInput("Label", "Enter the label:", "A")
shinyApp(ui, server)

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download