Reputation: 407
I am trying to add an input file in a flexdashboard, but I am a little confused. Previously I created a function to generate a plot, and then I call the function renderPlot with the function in order to get the plot in the dashboard.
R flexdashboard and shiny interactive plot
But now, If I create a function to read the file I don´t understand how to call it.
How to follow the same idea, create a function that read a file with an input file in the dashboard and then perform the analysis in the dashboard.
I have generated this code
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
```
Column {.sidebar}
-----------------------------------------------------------------------
```{r, echo = FALSE}
fileInput("file1", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv"))
```
With this I have obtained a side bar with the File Input. but how to use that uploaded file in any analysis and show the results in the dashboard?
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
```
Column {.sidebar}
-----------------------------------------------------------------------
```{r, echo = FALSE}
fileInput("file1", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv"))
df_reac <- reactive({
read_xlsx(file1$datapath)
})
```
Column{data-width=300}
-----------------------------------------------------------------------
```{r, echo = FALSE}
renderTable(df_reac)
```
Upvotes: 4
Views: 2913
Reputation: 1120
This is an old question but this code will let you upload files on Flexdashboard:
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
```
```{r}
dataset <- eventReactive(input$file1,{
dataset <- read.csv(input$file1$datapath)
})
```
# Column {.sidebar}
```{r, echo = FALSE}
fileInput("file1", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv"))
```
# Data
## Row
### Table 1 - Show the data recently acquired
```{r}
renderTable({
dataset <- dataset()
dataset
})
```
The main issue was to create a reactive function, since you don't know about the dataset until you upload the file. The reactive value is input$file1
Upvotes: 5