在R/Shiny中,我正在通过各种包制作一些非常详细的htmlwidgets,并且往往需要很长时间才能渲染。我想创建一个加载进度条或使用加载gif来让用户知道它正在加载...并且要耐心等待它加载完成。下面是使用dygraphs包的示例,一旦开始包含更多数据,即将滑块向上移动...加载时间会变得越来越长...我不确定如何将进度指示器(http://shiny.rstudio.com/articles/progress.html)合并到其中...但我愿意接受其他关于演示加载指示器的建议...
# load libraries
require(dygraphs)
require(shiny)
require(xts)
# create a simple app
runApp(list(
ui = bootstrapPage(
sliderInput('n', '10 to the power x', min=2,max=7,value=2),
dygraphOutput('plot1')
),
server = function(input, output) {
output$plot1 <- renderDygraph({
v <- 10^(input$n)
out <- dygraph(xts(rnorm(v),Sys.time()+seq(v))) %>%
dyRangeSelector()
return(out)
})
}
))
* 编辑 *
我根据@Carl在评论中的建议尝试了以下内容...但似乎没有起作用...请参见下文...
# load libraries
require(dygraphs)
require(shiny)
require(shinydashboard)
require(xts)
# create a simple app
ui <- dashboardPage(title='Loading graphs',
dashboardHeader(
title = 'Loading Graphs'
),
dashboardSidebar(
sliderInput('n', '10 to the power x', min=2,max=7,value=2)
),
dashboardBody(
tags$head(tags$style(type="text/css", "
#loadmessage {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
padding: 5px 0px 5px 0px;
text-align: center;
font-weight: bold;
font-size: 100%;
color: #000000;
background-color: #CCFF66;
z-index: 105;
}
")),
dygraphOutput('plot1'),
conditionalPanel(condition="$('html').hasClass('shiny-busy')",
tags$div("Loading...",id="loadmessage"))
)
)
server <- function(input, output) {
output$plot1 <- renderDygraph({
v <- 10^(input$n)
out <- dygraph(xts(rnorm(v),Sys.time()+seq(v))) %>%
dyRangeSelector()
return(out)
})
}
shinyApp(ui=ui,server=server)
以下也没有:
# load libraries
require(dygraphs)
require(shiny)
require(shinydashboard)
require(xts)
# create a simple app
ui <- dashboardPage(title='Loading graphs',
dashboardHeader(
title = 'Loading Graphs'
),
dashboardSidebar(
sliderInput('n', '10 to the power x', min=2,max=7,value=2)
),
dashboardBody(
tags$head(tags$style(HTML("
.progress-striped .bar {
background-color: #149bdf;
background-image: -webkit-gradient(linear, 0 100%, 100% 0, color-stop(0.25, rgba(255, 255, 255, 0.6)), color-stop(0.25, transparent), color-stop(0.5, transparent), color-stop(0.5, rgba(255, 255, 255, 0.6)), color-stop(0.75, rgba(255, 255, 255, 0.6)), color-stop(0.75, transparent), to(transparent));
background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, 0.6) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.6) 50%, rgba(255, 255, 255, 0.6) 75%, transparent 75%, transparent);
background-image: -moz-linear-gradient(45deg, rgba(255, 255, 255, 0.6) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.6) 50%, rgba(255, 255, 255, 0.6) 75%, transparent 75%, transparent);
background-image: -o-linear-gradient(45deg, rgba(255, 255, 255, 0.6) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.6) 50%, rgba(255, 255, 255, 0.6) 75%, transparent 75%, transparent);
background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.6) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.6) 50%, rgba(255, 255, 255, 0.6) 75%, transparent 75%, transparent);
-webkit-background-size: 40px 40px;
-moz-background-size: 40px 40px;
-o-background-size: 40px 40px;
background-size: 40px 40px;
}"))),
dygraphOutput('plot1')
)
)
server <- function(input, output) {
output$plot1 <- renderDygraph({
v <- 10^(input$n)
withProgress(message = 'Making plot', value = 1, {
out <- dygraph(xts(rnorm(v),Sys.time()+seq(v))) %>%
dyRangeSelector()
})
return(out)
})
}
shinyApp(ui=ui,server=server)
* 编辑2 *
类似于这个问题的解决方案是否可用?
shinydashboard
使用的类名与基本的shiny
不同,所以它可能不是shiny-busy
,而是其他类似于shinydashboard-busy
的名称,但我可能错了。 - Carlshinydashboard
没有 HTML 的 "busy" 类,因此您需要采用不同的方法。也许使用shinyjs
是解决问题的方法:https://github.com/daattali/shinyjs#usage-dashboard - Carl