Load an example data on file upload menu Shiny

I need to load an example data on file upload menu (fileInput) with help of checkboxInput.If user is selected the example box some data have to load into fileInput How it is possible?

 ui <- fluidPage(
 fileInput('inFile', 'Choose file'),
 checkboxInput(inputId = "Load",label = strong("Load Example Data"),value = FALSE,width    ='100%'),
 actionButton('reset', 'Reset'),
 server <- function(input, output, session) {
 rv <- reactiveValues(data = NULL)
 rv$data <- read.csv(input$inFile$datapath)})
 observeEvent(input$reset, {
 rv$data <- NULL
 output$tbl <- renderTable({
 shinyApp(ui, server)

Wouldn't the point of example data be to use a dataset already loaded as an example to the environment, therefore bypassing file input all together? I think that's what most users would assume.

Just want to show user how and which format he/she can input data for the analysis

So.perhaps you want a download button to help them download an example file with correct format. That they can then manually use in the fileinput

That will also work, But it will be easy instead of downloading, if you click on the checkboxInput the data automatically loads into fileinput.

I dont see how the user will understand or learn anything from that..
but ok. I dont think you can guarantee that the client machine will have any particular file, so if you example file is server side that will require a shinyFiles::shinyFilesButton with shinyFiles::shinyFileChoose implementation. Also you will probably need to write some javascript to drive the shinyFilesButton.

1 Like

This topic was automatically closed 54 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.