加载闪亮仪表板的页面

时间:2017-11-16 19:56:53

标签: r shiny shinydashboard shinyjs

我正在尝试为我的信息中心创建一个加载页面,但我似乎无法让它工作。我按照这里的例子; Shiny Dashboard - display a dedicated "loading.." page until initial loading of the data is done但它适用于流畅的页面,而不是闪亮的仪表板,我无法弄清楚如何调整它。

任何帮助将不胜感激!

我希望加载页面只是一个流畅的页面(没有标题或侧边栏),然后让我的主仪表板具有闪亮的仪表板方面。

额外:如果我可以在加载屏幕上添加一个gif,那就太棒了。类似的东西:

<iframe src="https://giphy.com/embed/BlmF3MhGfa4SY" width="480" height="360" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/plane-BlmF3MhGfa4SY">via GIPHY</a></p>

[破]

library (shiny)
library (shinydashboard)
library(shinyjs)


rm(list=ls())

appCSS <- "
#loading_page {
  position: absolute;
  background: #000000;
  opacity: 0.9;
  z-index: 100;
  left: 0;
  right: 0;
  height: 100%;
  text-align: center;
  color: #FFFFFF;
}
"
header <- dashboardHeader()
sidebar <- dashboardSidebar()
body <- dashboardBody("It worked!")


ui <- dashboardPage(
  useShinyjs(),
  inlineCSS(appCSS),
  div(
    id = "loading_page",
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody("Loading...")
  ),
  hidden(
    div(
      id = "main_content",
      header, sidebar, body
    )
  )
)


server = function(input, output, session) {
    # Simulate work being done for 4 second
    Sys.sleep(4)

    hide("loading_page")
    show("main_content") 
  }

shinyApp(ui, server)

2 个答案:

答案 0 :(得分:3)

试试这个图书馆shinycssloaders

library(shiny)
library(shinycssloaders)
library(highcharter)

ui <- fluidPage(
        mainPanel(
                plotOutput("my_plot")  %>% withSpinner(color="#0dc5c1")
        )
)

server <- function(input, output){

        output$my_plot <- renderPlot({
                Sys.sleep(1)
                plot(mtcars)})
}

shinyApp(ui, server)

答案 1 :(得分:0)

尝试使用此库:waiter 使用最少的代码即可轻松使用。带有多个加载动画。

用法:

library(shiny)
library(waiter)

ui <- fluidPage(
  use_waiter(),
  actionButton("show", "Show loading for 5 seconds")
)

server <- function(input, output, session){
  observeEvent(input$show, {
    show_waiter(spin_fading_circles())
    Sys.sleep(4)
    hide_waiter()
  })
}

if(interactive()) shinyApp(ui, server)

链接:https://cran.r-project.org/web/packages/waiter/readme/README.html