I'm trying to make a reactive selectInput using Shiny in a flexdashboard document.
My first
selectInput
selects the type of Zone in a Marine Park.selectInput("Zone", label = "Marine Park Zoning:", choices = c("All", levels(EoTR$MarineParkZone)), selected = "All")
Then I use this input to create a reactive data frame with only the Zones selected in step 1.
zone.choices = reactive({ if (input$Zone=="All"){ select(EoTR, ReefName, MarineParkZone, MarineParkMgmtSection) }else{ select(EoTR, ReefName, MarineParkZone, MarineParkMgmtSection)%>% filter(MarineParkZone==input$Zone)} })
Then I try to use this reactive data frame to define my choices for the next
selectInput
reactive({ selectInput("Reef", label = "Priority Reef:", choices = zone.choices()$ReefName, selected = "Arlington Reef (16-064)") })
When I run the document my second input displays a bunch of code instead of the select menu and therefore all the processes based from that selector fail.
Below is some code that will reproduce the problem
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r}
library(flexdashboard)
library(dplyr)
EoTR = data.frame(ReefName=c("Reef1", "Reef2", "Reef3", "Reef4"),
MarineParkZone=c("Fished", "Fished", "Un-Fished", "Un-Fished"))
selectInput("Zone", label = "Marine Park Zoning:",
choices = c("All", levels(EoTR$MarineParkZone)), selected = "All")
zone.choices = reactive({
if (input$Zone=="All"){
select(EoTR, ReefName, MarineParkZone)
}else{
select(EoTR, ReefName, MarineParkZone)%>%
filter(MarineParkZone==input$Zone)}
})
reactive({
selectInput("Reef", label = "Priority Reef:",
choices = zone.choices()$ReefName, selected = "Reef1")
})
```
I know it's probably something silly with how I'm defining my reactive input but I'd really appreciate any help on this.
Cheers,
Sam
Here is the solution for you:
The problem was with your
selectInput("Reef"...)
, you have set it to be reactive (which is inccorect) --> you should rather render it as UI object (renderUI
).