Shiny - Reactive Data

Hello,

Is there a simple way of pressing an action button, that imports a csv? I've created this via fileInput() however cant seem to crack how you would press a button to make it a reactive dataframe?

I'm trying to give the user the option of either importing via fileInput or uploading a standard template.

The datatable should accept either the fileInput or the actionButton template.

output$table <- renderReactable({
        reactable(datatable())

Any suggestions welcome!! Thank you.

I am not totally sure I do understand you, but you can create a reactive dataframe from shiny::fileInput, see below. Why do you need a separate actionButton?

library(shiny)
library(reactable)

ui <- fluidPage(
    sidebarLayout(
        sidebarPanel(
            fileInput("file1", "Choose CSV File", accept = ".csv"),
            checkboxInput("header", "Header", TRUE)
        ),
        mainPanel(
            reactableOutput("table")
        )
    )
)

server <- function(input, output) {

    datatable <- reactive({
        file <- input$file1
        ext <- tools::file_ext(file$datapath)

        req(file)
        validate(need(ext == "csv", "Please upload a csv file"))

        read.csv(file$datapath, header = input$header)
    })

    output$table <- renderReactable({
        reactable(datatable())
    })
}
shinyApp(ui, server)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.