【问题标题】:Showing "Loading" when download button is running in R server and hidden messages when finishing the task在 R 服务器中运行下载按钮时显示“正在加载”,完成任务时显示隐藏消息
【发布时间】:2020-10-21 06:54:17
【问题描述】:

我正在尝试创建一个闪亮的应用程序,它可以从数据库中下载文件,但查询时间很长,所以我想让用户知道,在他们按下按钮后,网络浏览器会显示“正在加载给用户",下载完成后,“正在加载”将被隐藏。

这是我的代码:

if (interactive()) {
  
  library(shiny)
  library(shinyWidgets)
  
  ui <- fluidPage(
    downloadBttn(
      outputId = "downloadData",
      style = "bordered",
      color = "primary"
    )
  )
  
  server <- function(input, output, session) {
    data_xi <- data.frame(s = c(1:3),r = c(4:6), x =c(19:21))
    
    observeEvent(input$downloadData, {
      showModal(modalDialog("Loading", footer=NULL))
      
      filename = function() {
        paste('data-', Sys.Date(), '.csv', sep='')
      }
      
      content = function(file) {
        write_xlsx(data_xi,file)
      }
      
      removeModal()
    })
  }
  shinyApp(ui, server)
  
}

【问题讨论】:

    标签: r shiny shinyapps


    【解决方案1】:

    可能是这样的:

    library(shiny)
    
    ui <- fluidPage(
      downloadBttn(
        outputId = "downloadData",
        style = "bordered",
        color = "primary"
      )
    )
    
    server <- function(input, output, session) {
      data_xi <- data.frame(s = c(1:3),r = c(4:6), x =c(19:21))
      
      output$downloadData <- downloadHandler(
        filename = function() {
          paste('data-', Sys.Date(), '.csv', sep='')
        },
        content = function(file) {
          showModal(modalDialog("Loading", footer=NULL))
          on.exit(removeModal())
          write.csv(data_xi,file)
        }
      )
    }
    
    shinyApp(ui,server)
    

    【讨论】:

      猜你喜欢
      • 2013-06-23
      • 2011-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多