I'm building a R Markdown flexdashboard and I'm having a problem to make an interactive boxplot, ...
Background:
The database "yield" includes:
-
Four continuous variables named
First.Step
,Second.Step
,Third.Step
,Overall.process
and to be selected separetaly as y-axis in my box plot usingselectInput Response
; -
Two categorical variables named
Flavor
andPlasma
and to be selected to change the values of my box plot withselectInput Flavor
andselectInput Plasma
; -
One categorical variable
Line
used as x-axis (fixed anytime).
In total, I have three selectInputs
placed in a side column to modify my boxplot.
Issue:
I can indeed use the selectInput Response
to select one of the four continuous variables. the box plot automatically changes and it's great! Now I would like to do the same with the other selectinputs
... but I'm struggling to find the answers here or there.
Code:
---
title: Dashboard
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
runtime: shiny
---
```{r load}
library(xlsx)
library(ggplot2)
yield <- read.csv("test.csv")
```
```{r inputs}
selectInput("Response", label = "Yield:",
choices = c("First.Step", "Second.Step", "Third.Step", "Overall.process"), selected = "Overall.process")
selectInput("Flavor", label = "P Flavor:",
choices = c("LA", "VN", "RI", "SQ"), selected = "LA")
selectInput("Plasma", label = "P Type:",
choices = c("SRC", "REC"), selected = "REC")
```
```{r boxplot}
renderPlot(
ggplot(yield,aes_string(yield$Line,y=input$Response, fill=yield$Line)) +
geom_boxplot(varwidth = TRUE, alpha=0.2) +
geom_jitter(color="black", width= 0.15, size=0.4, alpha=0.9) +
labs(fill="")
)
```
My guess is that I need to use the function reactive()
and create a subset including the other selectInputs. I've tried so many things. Currently my boxplot code only contains the selectInputs "Response" .. so no wonder it can't be changed with the two other selectInputs.
Being newbie, your help is more than welcome to answer the question and/or improve my coding skills. KR