R brilliant conditional value of the panel output

There are many questions about conditionalPanel in R shiny, but I still don’t understand how I can use the values ​​created by the .R server 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 session_id starts at 0, for example http://some-url.com/php/session_check.php?sid=00221245 , a string with the username (for example, 'testuser') is returned. When session_id starts with any number other than 0, for example http://some-url.com/php/session_check.php?sid=10221245 , returns 0. Now I would like to hide the panel, depending on whether the value is returned 0 or username. So I am trying to do something like this:

 conditionalPanel( condition="output.disable_ui!=0" 

I know this is wrong, but I really don’t understand how the condition argument works for outputs , will also work if I 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") ) )) 
+7
r shiny
source share
2 answers

I think that output should be displayed in Ui if you want to use it after conditionalPanel conditionalPanel .

In your example, the HTML for the conditional panel would look something like this:

<div data-display-if="output.disable_ui!=0">

If not a single element of your page (created as server-side outputs) has the identifier "disable_ui", then the condition "output.disable_ui! = 0" is always TRUE, and the conditional panel is 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 other than 0, a conditional panel is displayed. Now comment out the line verbatimTextOutput("id"), <div data-display-if="output.id!=0"> on this page there is no element with id, and then the conditionnal panel <div data-display-if="output.id!=0"> condition cannot be FALSE.

+7
source share

@Julien Navarre is right: the output must be visualized. suspendWhenHidden you set your suspendWhenHidden parameter 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) 
+10
source share

All Articles