I have a Shiny App that uploads a csv file that uploads a csv file.
library(shiny)
ui <- fluidPage(
fileInput("file_input","Choose your file in csv"),
textOutput("choose")
)
server <- function(input, output) {
output$choose <- reactive({
if(is.null(input$file_input))
{
"No input given yet."
}
else
{
"Action Button Appears!"
}
})
}
shinyApp(ui = ui, server = server)
What I want to do is if the data does not meet certain criteria (it must have a column named ID) then the upload fails with error message, and if the data is correct an action button appears for processing (only appears if data is fine else is hidden.
Thx!
You can use showModal
to show warning messages and you can use renderUI
to create button once you verify the file. I create one more button called uploa dfile so that I can use this to trigger an observeEvent
where I can run an if else
library(shiny)
library(tidyverse)
ui <- fluidPage(
fileInput("file_input", "Choose your file in csv",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
actionButton("p_file","Upload File"),
uiOutput("button_rui")
)
server <- function(input, output) {
observeEvent(input$p_file,{
if(is.null(input$file_input$datapath)){
showModal(modalDialog(
title = "Warning",
"Please upload a csv file",
easyClose = TRUE
))
} else{
input$file_input$datapath %>%
read_csv() -> df
if("ID" %in% colnames(df)){
output$button_rui <- renderUI(
actionButton("pp_file","Process File"),
)
} else {
showModal(modalDialog(
title = "Warning",
"File is not of correct format",
easyClose = TRUE
))
}
}
})
}
shinyApp(ui = ui, server = server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With