gpt4 book ai didi

r - Shiny 中的 conditionalPanel 不起作用

转载 作者:行者123 更新时间:2023-12-04 19:02:23 25 4
gpt4 key购买 nike

我正在尝试使用 conditionalPanel 在加载文件时显示消息。但是,一旦条件为真,面板就不会消失。我在下面创建了一个可重现的代码:

服务器

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) {

})

用户界面
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..")
)
)
)

最佳答案

条件提供给 conditionalPanel在 javascript 环境中执行,而不是在 R 环境中执行,因此无法在 R 环境中引用或检查变量或函数。您的情况的解决方案是使用 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)

关于r - Shiny 中的 conditionalPanel 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34658490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com