If I change both NY1 to NY2 to NY, i.e. not differentiate them explicitly, the program seems to behave differently. Is there a way to fix that?
library(shiny)
library(tidyverse)
state_lst <-list(
`East Coast` = c("NY" = "NY", "NJ" = "NJ", "CT" = "CT"),
`West Coast` = c("NY" = "NY", "OR" = "OR", "CA" = "CA"),
`Midwest` = c("MN" = "MN", "WI" = "WI", "IA" = "IA"))
shinyApp(
ui = fluidPage(
selectInput("state", "Choose a state:", state_lst),
textOutput("result")
),
server = function(input, output) {
output$result <- renderText({
region <-
state_lst %>%
purrr::keep(~ input$state %in% .x) %>%
names()
state <-
state_lst %>%
purrr::flatten_chr() %>%
purrr::keep(~ input$state %in% .x) %>%
names()
paste("You chose", region, "&", state, "from input:", input$state)
})
}