Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing reactive values to conditionalPanel condition

Tags:

r

shiny

I found a similar case here, not no concrete answer: shiny: passing reactiveValues to conditionalPanel but it gave me the idea that I need to set variable with session$sendCustomMessage in server.R and then extract it with Shiny.addCustomMessageHandler in ui.R. However, I can't figure out how to use the variable in the conditional panel.

Here is my contrived example (I know I can easily condition on input.select1, to get it working):

https://gist.github.com/anonymous/6013ffb888ef22b5aa110ddcafc5659a

Thanks

like image 844
Xlrv Avatar asked Aug 11 '16 11:08

Xlrv


1 Answers

If you want to send a Boolean value from server to client to determine the status of a conditionalPanel you can just use regular Shiny output, and tell Shiny to not suspend the value like so:

library(shiny)
server = shinyServer(function(input, output, session) {

  output$color_pr <- renderPrint({
    req(input$select1)
    input$select1
  })

  output$panelStatus <- reactive({
    input$select1=="show"
  })
  outputOptions(output, "panelStatus", suspendWhenHidden = FALSE)

})

ui=shinyUI(fluidPage(

  radioButtons("select1", "Show text?",
               c("Yes" = "show", "No" = "noshow")),

  conditionalPanel(

    condition = 'output.panelStatus'
    ,
    verbatimTextOutput("color_pr"))
))

shinyApp(ui=ui,server=server)
like image 139
Carl Avatar answered Oct 11 '22 13:10

Carl