Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditionalPanel in Shiny not working

Tags:

r

shiny

I am trying to use conditionalPanel to display message when a file is being loaded. However, the panel is not disappearing once the condition is TRUE. I have created a reproducible code below:

server.R

library(shiny)

print("Loading start")
print(paste("1->",exists('FGram')))
FGram <- readRDS("data/UGram.rds")
print(paste("2->",exists('FGram')))
print("Loading end")

shinyServer( function(input, output, session) {

})

ui.R

library(shiny)

shinyUI( fluidPage(
  sidebarLayout(
    sidebarPanel(
      h4("Side Panel")
      )
    ),

    mainPanel(
      h4("Main Panel"),
      br(),
      textOutput("First Line of text.."),
      br(),
      conditionalPanel(condition = "exists('FGram')", HTML("PLEASE WAIT!!     <br>App is loading, may take a while....")),
      br(),
      h4("Last Line of text..")
    )
  )
)
like image 465
PeterV Avatar asked Jan 07 '16 15:01

PeterV


1 Answers

Conditions supplied to conditionalPanel are executed in the javascript environment, not the R environment, and therefore cannot reference or inspect variables or functions in the R environment. A solution to your situation would be to use uiOutput, as in the example below.

myGlobalVar <- 1

server <- function(input, output) {

    output$condPanel <- renderUI({
        if (exists('myGlobalVar')) 
            HTML("PLEASE WAIT!!     <br>App is loading, may take a while....")
    })

}

ui <- fluidPage({
    uiOutput('condPanel')
})


shinyApp(ui=ui, server=server)
like image 78
Matthew Plourde Avatar answered Nov 15 '22 00:11

Matthew Plourde