【发布时间】:2016-11-15 07:52:12
【问题描述】:
在 R/Shiny 中,我正在制作一些非常详细的 htmlwidget,以通过各种包进入闪亮的应用程序,并且通常需要很长时间才能渲染。
我想创建一个加载栏或使用加载 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 在他的 cmets 中的建议尝试了以下操作....但它似乎不起作用...请参阅以下内容...
# 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)
* EDIT2 *
可以使用类似这个问题的解决方案吗?
How to display busy image when actual image is loading in client machine
【问题讨论】:
-
这就是您要找的东西? stackoverflow.com/questions/17325521/…
-
感谢您的建议,已编辑问题以显示我的尝试,但它看起来不像它的工作......
-
我猜
shinydashboard使用的类名称与基类shiny不同,所以不是shiny-busy,它可能是shinydashboard-busy之类的其他东西,但我可能错了 -
查看源代码后,
shinydashboard似乎没有 HTML“忙碌”类,因此您需要一种不同的方法。也许shinyjs的东西是要走的路:github.com/daattali/shinyjs#usage-dashboard -
如果您提供一个工作示例作为答案,我将非常乐意看看......