0
votes

I am trying to make a reactive UI with SelectInput in shiny. I have a server with renderUI selectizeInput (server.R), if I try to make two choices form the conditionalPanels call uiOutput, the server freezes (ui.R):

server.R

output$selz_01 <- renderUI({
  withProgress(message = 'Data is loading, please wait ...', value = 1:100, {
          selectizeInput(inputId="valuez01",
                   label="Select value 1:",
                   choices= unique(tab_01()$key),
                   selected =head(unique(tab_01()$key)),  
                   multiple = TRUE) 
}) })

output$selz_02 <- renderUI({
  withProgress(message = 'Data is loading, please wait ...', value = 1:100, {
          selectizeInput(inputId="valuez02",
                   label="Select value 2:",
                   choices= unique(tab_01()$measurements),
                   selected =head(unique(tab_01()$measurements)),  
                   multiple = TRUE) 
}) })

output$selz_03 <- renderUI({
  withProgress(message = 'Data is loading, please wait ...', value = 1:100, {
          selectizeInput(inputId="valuez03",
                   label="Select value 3:",
                   choices= unique(tab_01()$date),
                   selected =head(unique(tab_01()$date)),  
                   multiple = TRUE) 
}) })


ui.R

 radioGroupButtons(
                   inputId = "selChoices",
                   choiceNames =
                     list(icon("dice-one"), icon("dice-two"),
                          icon("dice-three")),
                   choiceValues =
                     list("one", "two", "three"),
                   label = "Choices", 
                   status = "default"
                 ),

conditionalPanel(
                  condition = "input.selChoices == 'one'",
                  uiOutput("selz_01"),
                  uiOutput("selz_02")
                 ),
conditionalPanel(
                  condition = "input.selChoices == 'two'",
                  uiOutput("selz_01"),
                  uiOutput("selz_03")
                 ),
conditionalPanel(
                  condition = "input.selChoices == 'three'",
                  uiOutput("selz_02"),
                  uiOutput("selz_03")
                 ),
1
Hi. You are using the same output name more than once in UI.R. That can hang the interfaceMiguel Suazo
Thanks a lot for your response!Kishore Kumar Jagadeesan

1 Answers

0
votes

It is best to use the output IDs only once in the ui as noted in the comments. You can give conditional output in renderUI. One way to do it is shown below.

ui <- fluidPage(
  radioGroupButtons(
    inputId = "selChoices",
    choiceNames =
      list(icon("dice-one"), icon("dice-two"),
           icon("dice-three")),
    choiceValues =
      list("one", "two", "three"),
    label = "Choices", 
    status = "default"
  ),
  uiOutput("selz_01"),
  uiOutput("selz_02"),
  uiOutput("selz_03")

)

server <- function(input, output, session) {
  
  tab_01 <- reactive({
    df <- gapminder[gapminder$continent=="Americas",]
    df$key <- df$country
    df$measurements <- df$lifeExp
    df$date <- df$year
    df
  })
  
  output$selz_01 <- renderUI({
    if (input$selChoices %in% c("one","two")) {
      withProgress(message = 'Data is loading, please wait ...', value = 1:100, {
        selectizeInput(inputId="valuez01",
                       label="Select value 1:",
                       choices= unique(tab_01()$key),
                       selected =head(unique(tab_01()$key)),  
                       multiple = TRUE) 
      }) 
    }else return(NULL)
    
  })
  
  output$selz_02 <- renderUI({
    if (input$selChoices %in% c("one","three")) {
      withProgress(message = 'Data is loading, please wait ...', value = 1:100, {
        selectizeInput(inputId="valuez02",
                       label="Select value 2:",
                       choices= unique(tab_01()$measurements),
                       selected =head(unique(tab_01()$measurements)),  
                       multiple = TRUE) 
      })
    }else return(NULL)
     
  })
  
  output$selz_03 <- renderUI({
    if (input$selChoices %in% c("three","two")) {
      withProgress(message = 'Data is loading, please wait ...', value = 1:100, {
        selectizeInput(inputId="valuez03",
                       label="Select value 3:",
                       choices= unique(tab_01()$date),
                       selected =head(unique(tab_01()$date)),  
                       multiple = TRUE) 
      }) 
    }else return(NULL)
  })
  
}

shinyApp(ui, server)