5
votes

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

1

1 Answers

22
votes

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)