cssearcy / AYS-R-Coding-SPR-2020

Coding in R for Policy Analytics
https://cssearcy.github.io/AYS-R-Coding-SPR-2020/
3 stars 3 forks source link

Final Project #40

Open zbell3 opened 2 years ago

zbell3 commented 2 years ago

I'm having issues getting my dashboard to work with multiple commands (e.g. age group and day of the week).

I can get it to work with one, in this case "age group", but while the checkboxes show up for "days of the week", when you check one nothing happens. Any thoughts?

Code:

selectInput(inputId = "age.cat", label = h3("Age Group"), choices = c("Youth", "Young Adult","Adult", "Senior"), selected = c("Youth"))

checkboxGroupInput(inputId = "days", label = h3("Day of Week"), choices = list("Monday" = "Mon", "Tuesday" = "Tue", "Wednesday" = "Wed", "Thursday" = "Thu", "Friday" = "Fri", "Saturday" = "Sat", "Sunday" = "Sun" ), selected = c("Fri", "Sat", "Sun"))

renderLeaflet({

d14 <- dat %>% filter(age.cat %in% input$age.cat, day %in% input$days) ....

lecy commented 2 years ago

My best advice is to create placeholder variables for your inputs so that you can assign value that you know work, then replace them with widget inputs.

Will help you at least figure out where the bug is.

widget.age.cat <- "Youth"  # temporary
# replace with:
# widget.age.cat <- input$age.cat  

widget.days <- c("Mon","Tue")
# replace with:
# widget.days <- input$days 

d14 <- 
  dat %>%
  filter( age.cat %in% widget.age.cat ,  day %in% widget.days ) 

# print head( d14 )

This allows you to isolate problems with input widgets from problems with analysis steps, and later with render steps.

If the subset is working, then add a render table option to print d14 and integrate your widgets.

If the widgets work, then integrate the leaflet component.

You have to break complex code apart to isolate each piece separately. No other way to debug something like this.

That said, you might check the syntax for a compound logical statement. Pretty sure you can't pass multiple logical vectors to a dplyr::filter() function.

age.cat %in% widget.age.cat ,  day %in% widget.days