'R Shiny ConditionalPanel based on Server value / Reactive value

I've got a problem I can't figure out. I've got a dataset in my shiny application with instructions for orders so to speak (called an SPO). The user puts in an SPO Number, we then retrieve all necessary instructions for the order and they finish the request and submit it through Shiny.

For one of the instructions we need to ask some additional questions to the user putting in the request. I am trying to make these additional questions show using a conditional panel.

Example code:

library(shiny)
library(tidyverse)

TestData <- tibble(SPO = c(101, 102),
                   HandRail = c(0, 1))

ui <- fluidPage(
  
    titlePanel("Order Acceptance"),
   
    sidebarLayout(
      sidebarPanel(
        numericInput("SPONumber",
                     "SPO",
                     value = NULL,
                     step = 1),
        
        conditionalPanel(
          condition = "output.HandRail",
          checkboxInput("MobileHandrail", "Mobile Handrail Allowed?", value = FALSE, width = NULL))
        ),
    
    mainPanel(
      h3(textOutput("OutputText", container = span))
    )
    )
)
# Define server logic
server <- function(input, output, session) {
  
  output$HandRail <- reactive({
    
    HandRailNeeded <- ifelse(input$SPONumber > 0 &
      input$SPONumber %in% TestData$SPO & 
      TestData$Handrail[TestData$SPO == input$SPONumber] == 1,
      TRUE,
      FALSE)
    
    return(HandRailNeeded)
  })
  

  outputOptions(output, "HandRail", suspendWhenHidden = FALSE)
  
  OutputText <- renderText({"Just to serve as mainpanel"})
  
}

# Run the application 
shinyApp(ui = ui, server = server)

So for SPO 101 I do not want to see the checkbox, and for 102 I do.

I've read some answers like Passing reactive values to conditionalPanel condition

But for some reason that doesn't solve it for me.

Really appreciate the help!

Bob



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source