Insert a file upload widget. Insert a selection box with options "Choice A" and "Choice B". Insert an actionbutton. When the button is pressed, display a warning modal if "Choice A" is selected. If "Choice A" is selected, display the uploaded file as a table.
Drop files here
or click to upload
library(shiny)
ui <- fluidPage(
fileInput("file", "Choose a file"),
selectInput("choice", "Make a choice:",
choices = c("Choice A", "Choice B")),
actionButton("submit", "Submit"),
tableOutput("filecontents")
)
server <- function(input, output) {
observeEvent(input$submit, {
if(input$choice == "Choice A") {
showModal(modalDialog(
title = "Warning",
"You selected Choice A!",
easyClose = TRUE
))
# Only show table if there's a file and Choice A is selected
output$filecontents <- renderTable({
req(input$file)
read.csv(input$file$datapath)
})
}
})
}
shinyApp(ui = ui, server = server)
Hi! I can help you with any questions about Shiny and R. What would you like to know?