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

Connecting Input & Output in Dashboard #27

Open SalvadorW2 opened 3 years ago

SalvadorW2 commented 3 years ago

Hello, I'm having trouble connecting my input and output in the dashboard.

Here is my input:

selectInput(inputId = "driver.1.alcohol", label = h4("Driver 1: Influence of Alcohol"), choices = c("No Apparent Influence","Alcohol"), selected = c("No Apparent Influence"))

selectInput(inputId = "driver.2.alcohol", label = h4("Driver 2: Influence of Alcohol"), choices = c("No Apparent Influence","Alcohol"), selected = c("No Apparent Influence"))

selectInput(inputId = "driver.1.drugs", label = h4("Driver 1: Influence of Drugs"), choices = c("No Apparent Influence","Drugs"), selected = c("No Apparent Influence"))

selectInput(inputId = "driver.2.drugs", label = h4("Driver 2: Influence of Drugs"), choices = c("No Apparent Influence","Drugs"), selected = c("No Apparent Influence"))

Here is my output:

renderLeaflet({

d2 <- dat %>% filter(AlcoholUse_Drv1 %in% input$driver.1.alcohol, AlcoholUse_Drv2 %in% input$driver.2.alcohol, DrugUse_Drv1 %>% input$driver.1.drugs, DrugUse_Drv2 %>% input$driver.2.drugs)

Any help would be appreciated, thank you.

SalvadorW2 commented 3 years ago

Alright, I've corrected the output as follows:

DrugUse_Drv1 %in% input$driver.1.drugs, DrugUse_Drv2 %in% input$driver.2.drugs

jamisoncrawford commented 3 years ago

Hi Sean,

Are you intending to use the original variables or the new variables d1.substance and d2.substance? If the latter:

Did you implement the code in issue #24 ? These variables will be troublesome without them.

If the former, what are you expecting to happen and what is happening instead? What error message are you getting, if any? What is displayed? Do the input widgets function and does the output draw a map?

Also, is there a reason you're using radio buttons and not checkboxGroupInput() for multiple options? That might make for a cleaner interface.

For radio buttons, == is better than %in% since it's a forced choice. %in% is best for check boxes and multiple values.

Another method for trouble shooting is renaming d2 in your output code to something new, like d9. You'll have to change it multiple times in the chunk. Maybe I'm superstitious but that has helped me in the past.

SalvadorW2 commented 3 years ago

I did implement the code in #24.

I used the former and now it seems to be working.

Thank you

jamisoncrawford commented 3 years ago

You're welcome! What ended up fixing it? Just for my knowledge and future reference?

SalvadorW2 commented 3 years ago

I just made the variables exactly equal the inputs.

jamisoncrawford commented 3 years ago

Thanks for getting back to us, Sean!

On Fri, Jul 31, 2020, 7:31 PM S Waggoner notifications@github.com wrote:

I just made the variables exactly equal the inputs.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cssearcy/AYS-R-Coding-SPR-2020/issues/27#issuecomment-667426227, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADXLEPBLM53SE2GNZPDGEKLR6NH53ANCNFSM4POKPEUQ .