整套反应功能的闪亮应用程序进度条
Shiny app progress bar for whole set of reactive functions
我正在开发一个闪亮的应用程序,用户可以从下拉菜单中选择一个基因,点击提交按钮,然后显示该基因的一组不同图表。生成所有这些图表的计算需要一些时间,我希望 Shiny 显示一个进度条或一些它忙碌的通知,以便用户远离提交按钮。
我在 Shiny 中找到了 withProgress() 和 Progress 对象,但是 - 如果我做对了 - 它们总是必须放在一个反应函数中,然后显示该函数的进度。但是,我有一整套不同的 renderPlot() 函数需要处理,我想显示所有这些函数的累积进度。
在网上搜索的时候我还找到了ShinySky这个包,里面好像有一个busyIndicator,可以设置当Shiny忙碌超过一定时间时开启。但是,当我尝试安装它时收到错误消息 "package ‘shinysky’ is not available (for R version 3.3.1)"。
我使用带有时间延迟的 nycflights13 天气数据生成了一个小型虚拟应用程序,以说明更改输入后绘图的刷新:
library(shiny)
library(nycflights13)
ui <- fluidPage(
wellPanel(
fluidRow(
column(12, offset = 0,
titlePanel("Look up airport weather data"))),
fluidRow(
column(3, offset = 0,
selectizeInput(inputId = "airportName", label = "",
choices = c("EWR", "JFK", "LGA")))),
fluidRow(
column(12, offset = 0,
actionButton(inputId = "klickButton", label = "Submit")))),
fluidRow(
column(6, offset = 0,
plotOutput(outputId = "windHist")),
column(6, offset = 0,
plotOutput(outputId = "windData"))),
fluidRow(
column(6, offset = 0,
plotOutput(outputId = "precipData")),
column(6, offset = 0,
plotOutput(outputId = "tempData")))
)
server <- function(input, output) {
wSubset <- eventReactive(input$klickButton, {
subset(weather, weather$origin == input$airportName)})
output$windHist <- renderPlot({
Sys.sleep(1)
hist(wSubset()$wind_dir)})
output$windData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$wind_speed, wSubset()$wind_gust)})
output$precipData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$humid, wSubset()$precip)})
output$tempData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$temp, wSubset()$dewp)})
}
shinyApp(ui = ui, server = server)
我正在寻找一种显示进度条的方法,当第一个函数在点击提交按钮后变得忙碌时,该进度条开始显示,并一直持续到所有绘图完成。如果这变得太复杂,我也很乐意通过任何其他方式告诉用户某些事情实际上正在后台发生,因此需要一些耐心。
这是解决此问题的一种方法,但在每个图上都有一个微调器。完全基于this solution by Dean Atali. The JS code is needed to hide the spinner before the Submit button is clicked. Once the button is clicked the spinner will be showed. Put the spinner.gif和www文件夹中的JS代码
spinnerManage.js
$(document).ready(function() {
$('#klickButton').click(function() {
$(".loading-spinner").show();
});
});
$(document).on("shiny:connected", function(e) {
$(".loading-spinner").hide();
});
app.R
library(shiny)
library(nycflights13)
mycss <- "
.plot-container {
position: relative;
}
.loading-spinner {
position: absolute;
left: 50%;
top: 50%;
z-index: -1;
margin-top: -33px; /* half of the spinner's height */
margin-left: -33px; /* half of the spinner's width */
}
"
ui <- fluidPage(
tags$head(tags$style(HTML(mycss)),
includeScript("./www/spinnerManage.js")),
wellPanel(
fluidRow(
column(12, offset = 0,
titlePanel("Look up airport weather data"))),
fluidRow(
column(3, offset = 0,
selectizeInput(inputId = "airportName", label = "",
choices = c("EWR", "JFK", "LGA")))),
fluidRow(
column(12, offset = 0,
actionButton(inputId = "klickButton", label = "Submit")))),
fluidRow(
column(6, offset = 0,
div(class = "plot-container",
tags$img(src = "spinner.gif",
class = "loading-spinner"),
plotOutput(outputId = "windHist"))
),
column(6, offset = 0,
div(class = "plot-container",
tags$img(src = "spinner.gif",
class = "loading-spinner"),
plotOutput(outputId = "windData"))
)),
fluidRow(
column(6, offset = 0,
div(class = "plot-container",
tags$img(src = "spinner.gif",
class = "loading-spinner"),
plotOutput(outputId = "precipData"))
),
column(6, offset = 0,
div(class = "plot-container",
tags$img(src = "spinner.gif",
class = "loading-spinner"),
plotOutput(outputId = "tempData"))
))
)
server <- function(input, output) {
wSubset <- eventReactive(input$klickButton, {
subset(weather, weather$origin == input$airportName)})
output$windHist <- renderPlot({
Sys.sleep(1)
hist(wSubset()$wind_dir)})
output$windData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$wind_speed, wSubset()$wind_gust)})
output$precipData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$humid, wSubset()$precip)})
output$tempData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$temp, wSubset()$dewp)})
}
shinyApp(ui = ui, server = server)
我正在开发一个闪亮的应用程序,用户可以从下拉菜单中选择一个基因,点击提交按钮,然后显示该基因的一组不同图表。生成所有这些图表的计算需要一些时间,我希望 Shiny 显示一个进度条或一些它忙碌的通知,以便用户远离提交按钮。
我在 Shiny 中找到了 withProgress() 和 Progress 对象,但是 - 如果我做对了 - 它们总是必须放在一个反应函数中,然后显示该函数的进度。但是,我有一整套不同的 renderPlot() 函数需要处理,我想显示所有这些函数的累积进度。
在网上搜索的时候我还找到了ShinySky这个包,里面好像有一个busyIndicator,可以设置当Shiny忙碌超过一定时间时开启。但是,当我尝试安装它时收到错误消息 "package ‘shinysky’ is not available (for R version 3.3.1)"。
我使用带有时间延迟的 nycflights13 天气数据生成了一个小型虚拟应用程序,以说明更改输入后绘图的刷新:
library(shiny)
library(nycflights13)
ui <- fluidPage(
wellPanel(
fluidRow(
column(12, offset = 0,
titlePanel("Look up airport weather data"))),
fluidRow(
column(3, offset = 0,
selectizeInput(inputId = "airportName", label = "",
choices = c("EWR", "JFK", "LGA")))),
fluidRow(
column(12, offset = 0,
actionButton(inputId = "klickButton", label = "Submit")))),
fluidRow(
column(6, offset = 0,
plotOutput(outputId = "windHist")),
column(6, offset = 0,
plotOutput(outputId = "windData"))),
fluidRow(
column(6, offset = 0,
plotOutput(outputId = "precipData")),
column(6, offset = 0,
plotOutput(outputId = "tempData")))
)
server <- function(input, output) {
wSubset <- eventReactive(input$klickButton, {
subset(weather, weather$origin == input$airportName)})
output$windHist <- renderPlot({
Sys.sleep(1)
hist(wSubset()$wind_dir)})
output$windData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$wind_speed, wSubset()$wind_gust)})
output$precipData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$humid, wSubset()$precip)})
output$tempData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$temp, wSubset()$dewp)})
}
shinyApp(ui = ui, server = server)
我正在寻找一种显示进度条的方法,当第一个函数在点击提交按钮后变得忙碌时,该进度条开始显示,并一直持续到所有绘图完成。如果这变得太复杂,我也很乐意通过任何其他方式告诉用户某些事情实际上正在后台发生,因此需要一些耐心。
这是解决此问题的一种方法,但在每个图上都有一个微调器。完全基于this solution by Dean Atali. The JS code is needed to hide the spinner before the Submit button is clicked. Once the button is clicked the spinner will be showed. Put the spinner.gif和www文件夹中的JS代码
spinnerManage.js
$(document).ready(function() {
$('#klickButton').click(function() {
$(".loading-spinner").show();
});
});
$(document).on("shiny:connected", function(e) {
$(".loading-spinner").hide();
});
app.R
library(shiny)
library(nycflights13)
mycss <- "
.plot-container {
position: relative;
}
.loading-spinner {
position: absolute;
left: 50%;
top: 50%;
z-index: -1;
margin-top: -33px; /* half of the spinner's height */
margin-left: -33px; /* half of the spinner's width */
}
"
ui <- fluidPage(
tags$head(tags$style(HTML(mycss)),
includeScript("./www/spinnerManage.js")),
wellPanel(
fluidRow(
column(12, offset = 0,
titlePanel("Look up airport weather data"))),
fluidRow(
column(3, offset = 0,
selectizeInput(inputId = "airportName", label = "",
choices = c("EWR", "JFK", "LGA")))),
fluidRow(
column(12, offset = 0,
actionButton(inputId = "klickButton", label = "Submit")))),
fluidRow(
column(6, offset = 0,
div(class = "plot-container",
tags$img(src = "spinner.gif",
class = "loading-spinner"),
plotOutput(outputId = "windHist"))
),
column(6, offset = 0,
div(class = "plot-container",
tags$img(src = "spinner.gif",
class = "loading-spinner"),
plotOutput(outputId = "windData"))
)),
fluidRow(
column(6, offset = 0,
div(class = "plot-container",
tags$img(src = "spinner.gif",
class = "loading-spinner"),
plotOutput(outputId = "precipData"))
),
column(6, offset = 0,
div(class = "plot-container",
tags$img(src = "spinner.gif",
class = "loading-spinner"),
plotOutput(outputId = "tempData"))
))
)
server <- function(input, output) {
wSubset <- eventReactive(input$klickButton, {
subset(weather, weather$origin == input$airportName)})
output$windHist <- renderPlot({
Sys.sleep(1)
hist(wSubset()$wind_dir)})
output$windData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$wind_speed, wSubset()$wind_gust)})
output$precipData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$humid, wSubset()$precip)})
output$tempData <- renderPlot({
Sys.sleep(1)
plot(wSubset()$temp, wSubset()$dewp)})
}
shinyApp(ui = ui, server = server)