Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny reactiveUI hangs with multiple uiOutput calls on same condition variable

Tags:

r

shiny

I am trying to make a reactive UI with sliders that drop in and out via a dropdown in shiny. I have a server with reactiveUI sliders (server.R):

library(shiny)
shinyServer(function(input, output) {
  output$slider1 <- reactiveUI(function() {
    sliderInput("s1", "slide 1", min = 1,  max = 100, value = 1)  
  })

  output$slider2 <- reactiveUI(function() {
    sliderInput("s2", "slide 2", min = 1,  max = 100, value = 1)   
  }) 
})

I can run the server fine with the following code (ui.R):

library(shiny)
shinyUI(pageWithSidebar(
  headerPanel("Hello Shiny!"),
  sidebarPanel(

    selectInput("dataset", "number of buckets:", 
                choices = c(1,2,3)),

    conditionalPanel(
      condition = "input.dataset==2",
      uiOutput("slider1"),uiOutput("slider2")),

    conditionalPanel(
      condition = "input.dataset==1",
      sliderInput("s1", "slide 1", min = 1,  max = 100, value = 1) 
      )
  ),
  mainPanel(
  )
))

but if I try to make both conditionalPanels call uiOutput, the server freezes:

library(shiny)
shinyUI(pageWithSidebar(
  headerPanel("Hello Shiny!"),
  sidebarPanel(

    selectInput("dataset", "number of buckets:", 
                choices = c(1,2,3)),

    conditionalPanel(
      condition = "input.dataset==2",
      uiOutput("slider1"),uiOutput("slider2")),

    conditionalPanel(
      condition = "input.dataset==1",
      uiOutput("slider1") 
      )
  ),
  mainPanel(
  )
))

I have played around with this, and found that it happens anytime that use the same condition variable and multiple uiOutput calls. Any suggestions? Thanks.

like image 236
Jim Crozier Avatar asked Feb 06 '13 16:02

Jim Crozier


1 Answers

See the comment from @Joe for the answer.

Basically, outputIDs and inputIDs have to be unique; two UI elements with the same IDs on the same page emits and error. This is a limitation of the reactivity in shiny.

The work around from @Jim is to create multiple elements for each output or input used by the client, e.g.

 output$slider2_1 <- ...
 output$slider2_2 <- ...
like image 124
ctbrown Avatar answered Nov 18 '22 01:11

ctbrown