上传完成后重新加载页面

Reload page when upload complete

我有一个用于上传 CSV 文件的闪亮应用程序。我使用 shinyWidgets 包中的函数 sendSweetAlert 来发送自定义消息,但我想在用户点击“确定”按钮时重新加载页面

我尝试使用 shinyalert 包中的 shinyalert,但我没有得到想要的结果。

这就是我所做的:

library(shiny)
library(shinyWidgets)
library(shinyalert)


ui <- fluidPage( 
  
  fileInput("file1", "Choose CSV File",
            multiple = FALSE,
            accept = c("text/csv",
                       "text/comma-separated-values,text/plain",
                       ".csv"),
            width = "80%")
)

server <- function(input, output,session) {
  
  # a progress bar
  observeEvent(
    input$file1,
    {  withProgress(message = "Progress...",value = 0, {
      for (i in seq_len(50)) {
        Sys.sleep(0.1)
        incProgress(1 / 50)
        
        setProgress(NULL, detail = paste(round(((i+1)*100/50),digits = 0),"%"))
      }
      
      setProgress(1, detail = "100%")
      
      # the custom message when progress reach 100%
      sendSweetAlert(
        session = session,
        title = "Great",
        text = "Done !",
        type = "success"
      )
      
      # my second attempt but doest work
      
      # shinyalert::shinyalert('Succes', callbackR = mycallback)
      # mycallback <- function(value) {
      #   "javascript:window.location.reload(true)"
      # }
      
      
    })}
  )
  
}

shinyApp(ui,server)

一些帮助将不胜感激

您可以在 shinyalert() 中使用 callbackJS:

server <- function(input, output,session) {
  
  # a progress bar
  observeEvent(
    input$file1,
    {  withProgress(message = "Progress...",value = 0, {
      for (i in seq_len(50)) {
        Sys.sleep(0.1)
        incProgress(1 / 50)
        
        setProgress(NULL, detail = paste(round(((i+1)*100/50),digits = 0),"%"))
      }
      
      setProgress(1, detail = "100%")
      

      shinyalert::shinyalert('Succes', callbackJS = "function() {location.reload()}")
      
    })}
  )
  
}

这样,当您在模式中单击“确定”时,页面将重新加载。