【发布时间】:2017-02-27 07:31:00
【问题描述】:
我正在使用 miniUI 构建一个闪亮的小工具。我想在小工具做一些准备工作并尝试实施这个简单方便的解决方案时显示一个加载屏幕:https://github.com/daattali/advanced-shiny/blob/master/loading-screen/app.R
以下是小工具外观的一个小示例:
library(shiny)
library(shinyjs)
library(miniUI)
sampleApp <- function() {
ui <- miniPage(
gadgetTitleBar("Sample App"),
miniTabstripPanel(
miniTabPanel(
"Panel 1",
fillCol(div("Content of Panel 1"))
),
miniTabPanel(
"Panel 2",
fillCol(div("Content of Panel 2"))
),
between = p("") # Needed later on to avoid error in shinyjs::hidden()
)
)
server <- function(input, output) {
}
runGadget(ui, server, viewer = dialogViewer("Sample dialog"))
}
sampleApp()
我尝试了几种方法来调整加载屏幕代码以适应我的示例。我似乎无法隐藏内容:
-
在 miniTabstripPanel() 周围放置 hidden():
library(shiny) library(shinyjs) library(miniUI) appCSS <- " #loading-content { position: absolute; background: #000000; opacity: 0.9; z-index: 100; left: 0; right: 0; height: 100%; text-align: center; color: #FFFFFF; } " sampleApp <- function() { ui <- miniPage( useShinyjs(), inlineCSS(appCSS), # Loading message div( id = "loading-content", h2("Loading...") ), # The main app code goes here gadgetTitleBar("AppTitle"), hidden( miniTabstripPanel( miniTabPanel( "Panel 1", fillCol(div("Content of Panel 1")) ), miniTabPanel( "Panel 2", fillCol(div("Content of Panel 2")) ), between = p("") # Needed later on to avoid error in shinyjs::hidden() ), id = "app-content" ) ) server <- function(input, output) { # Simulate work being done for 1 second Sys.sleep(1) # Hide the loading message when the rest of the server function has executed hide(id = "loading-content", anim = TRUE, animType = "fade") show("app-content") } runGadget(ui, server, viewer = dialogViewer("Sample dialog")) } sampleApp() 将内容包装在 div() 中。
- 根据这个答案使用 tagList() https://stackoverflow.com/a/32386689/5664232
【问题讨论】: