简体   繁体   English

条件面板在Shiny中不起作用

[英]conditionalPanel in Shiny not working

I am trying to use conditionalPanel to display message when a file is being loaded. 我正在尝试使用conditionalPanel在加载文件时显示消息。 However, the panel is not disappearing once the condition is TRUE. 但是,一旦条件为TRUE,面板不会消失。 I have created a reproducible code below: 我在下面创建了一个可重现的代码:

server.R 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 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..")
    )
  )
)

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. 提供给conditionalPanel在javascript环境中执行,而不是在R环境中执行,因此无法在R环境中引用或检查变量或函数。 A solution to your situation would be to use uiOutput , as in the example below. 您的情况的解决方案是使用uiOutput ,如下例所示。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM