【问题标题】:Show a message instead of/within plot while data is loading in R Shiny在 R Shiny 中加载数据时显示消息而不是绘图内/绘图内
【发布时间】:2023-03-23 16:49:01
【问题描述】:

在加载其他数据时,R Shiny 是否有可能用“正在加载”消息替换绘图?我在我的应用程序中使用了一个大数据集,由于并非总是需要所有数据,我将数据分成两部分,最初只加载一个较小的样本。

只有在下拉菜单中选择完整数据集时,我才会加载完整样本。由于加载需要一些时间并冻结情节,我想改为显示一条消息并仅在加载完成时显示情节。示例:

library(shiny)

ui <- fluidPage(
  selectInput("select_length","Length",choices = c("Short","Long"), multiple= FALSE, selected = "Short"),
  plotOutput("hist")
)

server <- function(input, output){
  rv <- reactiveValues()
  rv$df <- c(1,2)

  observeEvent(input$select_length,{
    Sys.sleep(5)
    df_new <- c(3,4)
    rv$df <- c(rv$df, df_new)
    },
    once = TRUE,
    ignoreInit = TRUE
  )

  output$hist <- renderPlot({
    barplot(rv$df)
  })
}

shinyApp(ui = ui, server = server)

我想在加载附加数据时显示一个带有简单“加载”消息的图,例如:

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')
text(x = 0.5, y = 0.5, paste("Data is loading..."), cex = 1.6, col = "black")

【问题讨论】:

标签: r shiny


【解决方案1】:

您可能喜欢 ShinyBS 软件包。我之前在加载数据时用它来发出警报,效果很好(看起来也很漂亮)。

这是我的使用示例....

这是用于创建警报的代码,非常简单。用户可以退出,也可以调用删除,详情如下。

服务器:

createAlert(session, 'upload_complete',title = 'Data Import Complete', content = 'You may continue to the other tabs', alertId = 'alert_delete', append = FALSE)

用户界面:

mainPanel(
....
bsAlert('upload_complete'),
)

调用删除(在服务器中)

closeAlert(session,'alert_delete')

【讨论】:

    【解决方案2】:

    在加载附加数据时显示进度条是否可以接受? Shiny RStudio 展示了一个显示绘图的示例 - http://shiny.rstudio.com/gallery/progress-bar-example.html

    【讨论】:

      猜你喜欢
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 2012-05-22
      • 2020-05-03
      • 2018-03-14
      • 1970-01-01
      • 2018-07-04
      • 2016-11-07
      相关资源
      最近更新 更多