I'm unable to make my leaflet map responsive to the user selected options from a dropdown. My map loads with static choices, but when I try to make it responsive to the user choices, it throws an error. It's basically the color palette of leaflet, which I'm not sure how to make reactive based on selectInput options. Would somebody please help?
## ui.R ##
library(shinydashboard)
library(leaflet)
dataset = c(a, b, c, d, e)
gender <- c("Male", "Female","Female", "Male")
Location <- c("AB", "BC", "CD", "DE")
hasJob <- c("Yes","Yes","No","No")
Latitude <- c(49.82380908513249,59.478568831926395,59.478568831926395,49.82380908513249)
Longitude <- c(-10.8544921875,-10.8544921875,2.021484375,2.021484375)
DF <- data.frame(gender,Location,hasJob,Latitude,Longitude)
ui <- dashboardPage(
dashboardHeader(title = "Dashboard",
titleWidth = 300),
dashboardSidebar(
selectInput(
inputId = "schemes",
label = "Select a Scheme",
choices = c("a","b","c", "d", "e"),
selected = "a",
selectize = FALSE
)
),
dashboardBody(
tabsetPanel(
id = "tabs",
tabPanel(
title = "Main Dashboard",
value = "page1",
fluidRow(
column(width = 9,
box(
width = NULL, solidHeader = TRUE, leafletOutput("mymap", height = 600, width = "100%"))),
column(width = 3,
box(
width= NULL,
selectInput('indicators', 'Select an indicator', "")), #indicators would load automatically as user select options above.
#This is second selectInput widget that will also impact how the Choropleth map loads.
box(
width= NULL,
selectInput("gender", 'Select gender', "")),
)))
)
)
Server.R
server <- function(input, output, session) {
outVar = reactive({
mydata = get(input$schemes)
myvars <- names(mydata)
})
observe({
updateSelectInput(session, "indicators",
choices = outVar()
)})
outVar2 = reactive({
mydata = get(input$schemes)
mydata$Year
})
observe({
updateSelectInput(session, "gender",
choices = outVar2()
)})
datasetInput <- reactive({
switch(input$schemes,
"a" = a,
"b" = b,
"c" = c,
"d" = d,
"e" = e
)
})
output$mymap <- renderLeaflet({
location <- "India"
geo <- geocode(location, limit = 1, key = "place")
qpal <- colorQuantile("viridis", domain = **"WHAT SHOULD GO HERE?"** , n = 5)
leaflet(datasetInput()) %>%
#addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addPolygons(stroke = TRUE,
weight = 1,
smoothFactor = 0.2,
fillOpacity = .9,
color = "white",
fillColor = ~qpal("**WHAT SHOULD GO HERE?**")) #%>%
#setView(lat = geo$lat, lng = geo$lon)
})
}
shinyApp(ui, server)