Reputation: 1445
I want to create a web app using flexdashboard so that people can upload their CSV and see the visualization.
Right now, I am using a R markdown with flexdashboard template. Here is the file upload code.
{r, echo = FALSE}
fileInput("file1", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv"))
My question is: in this .rmd notebook, how can I access users' uploaded file and read it as dataframe?
Upvotes: 1
Views: 373
Reputation: 462
The simplest way I know of is to do something like:
```{r, echo=FALSE}
library(shiny)
fileInput("file1", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")
)
values <- reactiveValues(df_data = NULL)
observeEvent(input$file1, {
values$df_data <- read.csv(input$file1$datapath)
})
renderTable(values$df_data)
```
You can really do whatever you'd like in that observeEvent
expression (i.e. data validation, filter, transform, etc.).
Upvotes: 1