# Generated by DropToApp library(shiny) library(bslib) ui <- page_sidebar( title = "CSV explorer", sidebar = sidebar( fileInput("file", "Upload a CSV file", accept = ".csv"), checkboxInput("header", "First row has column names", value = TRUE), radioButtons( "sep", "Separator", choices = c("Comma", "Semicolon", "Tab"), inline = TRUE ), downloadButton("download", "Download as CSV") ), layout_columns( value_box(title = "Rows", value = textOutput("rows"), theme = "primary"), value_box( title = "Columns", value = textOutput("cols"), theme = "secondary" ) ), navset_card_tab( nav_panel("Data", DT::DTOutput("table")), nav_panel("Summary", verbatimTextOutput("summary")) ) ) server <- function(input, output, session) { # Inputs: input$file, input$header, input$sep # Example data until a file is uploaded data <- reactive({ if (is.null(input$file)) { mtcars } else { sep <- switch(input$sep, Comma = ",", Semicolon = ";", Tab = "\t") read.csv(input$file$datapath, header = input$header, sep = sep) } }) output$rows <- renderText(nrow(data())) output$cols <- renderText(ncol(data())) output$download <- downloadHandler( filename = "data.csv", content = function(file) { write.csv(data(), file, row.names = FALSE) } ) output$table <- DT::renderDT({ data() }) output$summary <- renderPrint({ summary(data()) }) } shinyApp(ui, server)