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?

 library(shiny)
 library(shinyjs) 
 ui <- fluidPage(
 useShinyjs(),
 fileInput('inFile', 'Choose file'),
 checkboxInput(inputId = "Load",label = strong("Load Example Data"),value = FALSE,width    ='100%'),
 actionButton('reset', 'Reset'),
 tableOutput('tbl')) 
 server <- function(input, output, session) {
 rv <- reactiveValues(data = NULL)
 observe({
 req(input$inFile)
 rv$data <- read.csv(input$inFile$datapath)})
 observeEvent(input$reset, {
 rv$data <- NULL
 reset('inFile')})
 output$tbl <- renderTable({
 rv$data})}
 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

Hmmm
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