当用户在闪亮的应用程序中上传扩展名错误的文件时弹出显示
Display pop up when user uploads file with the wrong extension in shiny app
在下面的应用程序中,当用户未上传 .xls
文件时,我希望显示一个弹出窗口。现在它只出现在开头,但如果上传另一个让我们说 doc
文件它是隐藏的。我不在乎它是用 shinyalert
包还是其他方法。
library(shiny)
library(shinyalert)
ui <- fluidPage(
useShinyalert(), # Set up shinyalert
fileInput('file1', 'Choose xls file',
accept = c(".xls")
)
)
server <- function(input, output, session) {
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)
}
shinyApp(ui, server)
这也会重置 fileInput
:
library(shiny)
library(tools)
ui <- fluidPage(
uiOutput("fileUpload")
)
server <- function(input, output, session) {
showModal(modalDialog("My startup modal..."))
resetFileUpload <- reactiveVal(FALSE)
output$fileUpload <- renderUI({
resetFileUpload() # reactive dependency
resetFileUpload(FALSE)
fileInput('file1', 'Choose xls file', accept = c(".xls"))
})
observeEvent(input$file1, {
if(file_ext(input$file1$name) != "xls"){
resetFileUpload(TRUE)
showModal(modalDialog("That's not a .xls file"))
}
})
}
shinyApp(ui, server)
在下面的应用程序中,当用户未上传 .xls
文件时,我希望显示一个弹出窗口。现在它只出现在开头,但如果上传另一个让我们说 doc
文件它是隐藏的。我不在乎它是用 shinyalert
包还是其他方法。
library(shiny)
library(shinyalert)
ui <- fluidPage(
useShinyalert(), # Set up shinyalert
fileInput('file1', 'Choose xls file',
accept = c(".xls")
)
)
server <- function(input, output, session) {
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)
}
shinyApp(ui, server)
这也会重置 fileInput
:
library(shiny)
library(tools)
ui <- fluidPage(
uiOutput("fileUpload")
)
server <- function(input, output, session) {
showModal(modalDialog("My startup modal..."))
resetFileUpload <- reactiveVal(FALSE)
output$fileUpload <- renderUI({
resetFileUpload() # reactive dependency
resetFileUpload(FALSE)
fileInput('file1', 'Choose xls file', accept = c(".xls"))
})
observeEvent(input$file1, {
if(file_ext(input$file1$name) != "xls"){
resetFileUpload(TRUE)
showModal(modalDialog("That's not a .xls file"))
}
})
}
shinyApp(ui, server)