Observe function use with action button for data upload in shiny

shiny

#1

I am making a shiny app which requires a data upload panel and a button to automatically load the sample dataset.

The problem:

I want to create a upload panel which is controlled by an action button called "submit".
Also I need a button called "sample data" to automatically load a sample dataset for demonstration.

However, I found it hard to write a code section for this function, could anyone help?

my sample code to get a dataset which can be used for output in server.R:

data from upload

load_data <- eventReactive(input$submit_button, {
req(input$file1)
read.csv(input$file1$datapath,
header = input$header,
sep = input$sep,
quote = input$quote)
})

sample data

sample_data <- eventReactive(input$sample_button, {
read.csv("data/sample_data.csv")
})

observeEvents(input$sample_button,{df = sample_data)
observeEvents(input$submit_button,{df = load_data)

I am think it should involve the if/else statement but I am not sure how I add them into the observe environment.

Hao