簡體   English   中英

在 R 中加載數據時顯示消息而不是 plot Shiny

[英]Show a message instead of/within plot while data is loading in R Shiny

R Shiny 是否有可能在加載其他數據時用“正在加載”消息替換 plot? 我在我的應用程序中使用了一個大數據集,因為並非所有數據都是必需的,所以我將數據分成兩部分,最初只加載一個較小的樣本。

只有在下拉菜單中選擇完整數據集時,我才會加載完整樣本。 由於加載需要一些時間並凍結 plot,因此我想顯示一條消息,僅在加載完成后才顯示 plot。 例子:

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,例如:

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")

你可能會喜歡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')

是否可以在加載其他數據時顯示進度條? Shiny RStudio展示了一個顯示情節的例子 - http://shiny.rstudio.com/gallery/progress-bar-example.html

我建議使用庫(shinycssloaders)。

非常簡單和專業。

  1. library(shinycssloaders)
  2. 選項如: options(spinner.color="#0275D8", spinner.color.background="#ffffff", spinner.size=.5)
  3. 使用withSpinner(Output method(objectname), type = 1-8)添加加載器

https://www.listendata.com/2019/07/add-loader-for-shiny-r.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM