There are many questions about conditionalPanel
in R shiny, but I still don\'t understand how I can use values created by server.R for conditionalPanel
I think that the output
must be rendered in the UI if you want to use it after in the condition of a conditionalPanel
.
With you example, the HTML for the conditional panel will look like something like this :
<div data-display-if="output.disable_ui!=0">
If no elements in your page (created as outputs in the server side) have the id "disable_ui" then the condition "output.disable_ui!=0" is always TRUE, and the conditional panel always displayed.
A simple example :
shiny::runApp(list(
ui = pageWithSidebar(
headerPanel("test"),
sidebarPanel(
selectInput(
"var", "Var",
0:9)),
mainPanel(
verbatimTextOutput("id"),
conditionalPanel(
condition="output.id!=0",
h4('Visible')
)
)
),
server = function(input, output) {
output$id<-reactive({input$var})
}
))
If you select a number different of 0 the conditional panel will be displayed.
Now, comment the line verbatimTextOutput("id"),
, there is no more element with the id "id" in the page and then the condition of the conditional panel <div data-display-if="output.id!=0">
can't be FALSE.
This is the real answer to this question: Use this inside of your server function:
outputOptions(output, "outputId", suspendWhenHidden = FALSE)
You will then be able to use the output.item
in your conditionalPanel.
Answer from here: https://github.com/daattali/advanced-shiny/blob/master/server-to-ui-variable/app.R
And here: https://github.com/rstudio/shiny/issues/1318
@Julien Navarre is right: the output must be rendered. Except if you set its option suspendWhenHidden
to FALSE
:
output$disable_ui<-reactive({
query<-parseQueryString(clientData$url_search)
url_path<-paste(sep="","http://some-url.com/php/session_check.php?sid=",query, collapse="")
read.table(url_path)
})
outputOptions(output, 'disable_ui', suspendWhenHidden=FALSE)