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
. Here is what I would like to do: I have a URL like http://some-url.com/php/session_check.php?sid=session_id. When the session_id
starts with a 0, like http://some-url.com/php/session_check.php?sid=00221245 a string with a username is returned (e.g. 'testuser'). When the session_id starts with any other number but 0, like http://some-url.com/php/session_check.php?sid=10221245 a 0 is returned. Now I would like to hide a panel, depending on whether the a 0 or a username is returned. Therefore I try to do something like this:
conditionalPanel(
condition="output.disable_ui!=0"
I know that this is the wrong, but I don't really understand how the condition
argument works for outputs
, as the same would work if I would do this for any input
from ui.R
.
Here is my sample code:
server.R
library(shiny)
library(raster)
library(rgdal)
shinyServer(function(input, output, clientData) {
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)
})
data <- reactive({
inFile <- input$example_layer
if (is.null(inFile))
return(NULL)
raster.file<- raster(inFile$datapath)
})
output$raster.plot <- renderPrint({
"Nothing to see here"
})
})
ui.R
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("test"),
sidebarPanel(
conditionalPanel(
condition="output.disable_ui!=0",
#File Upload
fileInput('example_layer', 'Choose Raster Layer (ASCII)', multiple=FALSE, accept='asc')
)),
mainPanel(
verbatimTextOutput("raster.plot")
)
))
@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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With