Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R shiny conditionalPanel output value

Tags:

r

shiny

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")
  )
))
like image 911
viktor_r Avatar asked Feb 06 '14 17:02

viktor_r


1 Answers

@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)
like image 192
Stéphane Laurent Avatar answered Oct 19 '22 06:10

Stéphane Laurent