Re: [shinyapps-users] Depending Choose Prompt

18 views
Skip to first unread message

Tareef Kawaf

unread,
May 26, 2015, 8:46:15 AM5/26/15
to Karim Mezhoud, shiny-...@googlegroups.com
Cross posting to the shiny-discuss list since this is more of a shiny question.

On Mon, May 25, 2015 at 5:16 AM, Karim Mezhoud <kmez...@gmail.com> wrote:


Dear All,
I am thinking about depending Choose prompt (selectizeInput).
The second "Choose prompt" depends on the first one.
The first one list the Studies.
The second lists Cases depending which study is selected.

In the following code The Cases are specific for Study 4 (Studies[4,1]).

 I would like to change Studies[4,1] by a variable depending on which study is selected



Thanks
Karim

ui.R


 sidebarLayout(
   sidebarPanel(

# Select Studies
    selectizeInput('StudiesID', 'Studies 1', state.name, multiple = TRUE),


# Select Cases
  selectizeInput('CasesID', 'Cases 1', choices=NULL , multiple = TRUE),

))

mainPanel(
    verbatimTextOutput('Studies_values'),
   tableOutput('Cases_values')
)





server.R

 ## Select Studies
  library(cgdsr)
  cgds<-CGDS("http://www.cbioportal.org/public-portal/")
  Studies <- getCancerStudies(cgds)
  ##
  updateSelectizeInput(session, 'StudiesID', choices = Studies[,1])

  output$Studies_values <- renderPrint({
    list(List_Studies = input$StudiesID)

  })
  ## update Cases
#reactive({
  #output$cases <- renderPrint(input$cases)

  Cases <- getCaseLists(cgds,Studies[4,1])

  updateSelectizeInput(session, 'CasesID', choices = Cases[,1])

 output$Cases_values<- renderPrint({
   list(List_Cases = input$CasesID)
  })

--
You received this message because you are subscribed to the Google Groups "ShinyApps Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shinyapps-use...@googlegroups.com.
To post to this group, send email to shinyap...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shinyapps-users/8e9207c9-1bb9-4774-bcca-63d0ad5bfa06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dean Attali

unread,
May 26, 2015, 3:45:49 PM5/26/15
to shiny-...@googlegroups.com, kmez...@gmail.com
It's definitely doable, here's a rewrite of your app. Note that I moved the select inputs to be defined in the server and rendered as `renderUI` instead having them awkwardly defined in UI with random choices and then populating them with normal choices later.

runApp(shinyApp(
  ui = fluidPage(
    sidebarLayout(
      sidebarPanel(
        
        # Select Studies
        uiOutput("studyIdSelect"),
        
        # Select Cases
        uiOutput("caseIdSelect")
        
      ),
    
    mainPanel(
      verbatimTextOutput('Studies_values'),
      tableOutput('Cases_values')
    ))
    
    
  ),
  server = function(input, output, session) {
    ## Select Studies
    library(cgdsr)
    Studies <- getCancerStudies(cgds)
    
    output$studyIdSelect <- renderUI({
      selectizeInput('StudiesID', 'Studies 1', choices = Studies[, 1], multiple = TRUE)
    })

    output$Studies_values <- renderPrint({
      list(List_Studies = input$StudiesID)
    })
    
    output$caseIdSelect <- renderUI({
      Cases <- lapply(input$StudiesID, function(x) getCaseLists(cgds, x))
      Cases <- do.call(rbind, Cases)
      
      selectizeInput('CasesID', 'Cases 1', choices = Cases[, 1] , multiple = TRUE)
    })
    
    output$Cases_values<- renderPrint({
      list(List_Cases = input$CasesID)
    })
  }
))


The main bit of interest is

      Cases <- lapply(input$StudiesID, function(x) getCaseLists(cgds, x))
      Cases <- do.call(rbind, Cases)

Basically, whenever studies are chosen, we go through all the study ids, get all the cases for each study id, and then bind together the resulting dataframe

Karim Mezhoud

unread,
May 26, 2015, 3:58:20 PM5/26/15
to Dean Attali, shiny-...@googlegroups.com
Thanks Dean!
Reply all
Reply to author
Forward
0 new messages