闪亮的应用程序中依赖于 fileInput() 的闪亮模态

Shiny modal that is dependent on fileInput() in shiny app

我创建了一个模式,该模式在应用程序启动时激活,并警告用户他首先需要上传一个 excel 文件。但是当我上传它时,模式再次显示,这似乎是错误的。

library(shiny)
library(shinyalert)

ui <- fluidPage(
  useShinyalert(),  # Set up shinyalert
  fileInput('file1', 'Choose xls file',
            accept = c(".xls")
  )
)

server <- function(input, output, session) {
  observeEvent(is.null(input$file1), {
    # Show a modal when the button is pressed
    shinyalert("Oops!", "Something went wrong.", type = "error")
  })
}

shinyApp(ui, server)

也许你可以试试 if 条件。

observeEvent(input$file1, {
    if (is.null(input$file1))
    # Show a modal when the button is pressed
    shinyalert("Oops!", "Something went wrong.", type = "error")
  }, ignoreNULL = FALSE)