library(shiny)
ui <- fluidPage(
selectInput("num", "Choose a number", 1:10),
conditionalPanel(
condition = "output.square",
"That's a perfect square!"
)
)
server <- function(input, output, session) {
output$square <- reactive({
sqrt(as.numeric(input$num)) %% 1 == 0
})
outputOptions(output, 'square', suspendWhenHidden = FALSE)
}
shinyApp(ui = ui, server = server)
With that code (taken straight from https://github.com/daattali/advanced-shiny/blob/master/server-to-ui-variable/app.R), the conditional panel can depend a variable in the server. But is it not possible to use that variable anywhere else?
For example, I would like to replace "That's a perfect square!"
with paste("It is ", output.square, " that the number is a perfect square!")
but when I try to use output.square there I get an error that the variable is not defined. But clearly is it defined, since the condition is using it...