I have a data frame as follows:
d <- data_frame(number = 1:4,
date = c(1600, 1700, 1800, 1900),
T_name = c("name1", "name2", "name3", "name4"),
casualties= c(18, 89, 97, 34),
m_name= c("name1", "name2", "name3", "name4"),
longitude = c(87.7, 103.2, 67.0, 76.8),
latitude = c(23.4, 78.3, 78.9, 34.9))
I'm trying to get my map to react to a select input but when running the code I get the following error message:
Length of logical index vector must be 1 or 9 (the number of columns), not 25
There are 9 columns in my real data, and 25 rows, so this does make some sense. I just can't figure out how to amend my code. What I want is a drop down list sorted by unique T_name, and when a new T_name is selected the map updates with only data from that T_name.
UI
library(shiny)
library(leaflet)
ui <- {fluidPage("app title",
sidebarLayout(
sidebarPanel(
selectInput(inputId = "input1", label = "Name" ,choices =
unique(d$T_name))
),
mainPanel(
leafletOutput("mymap"))
)
)}
server
server <- function(input, output) {
react <- reactive({
req(input$input1)
df <- d[d$T_name == input$input1]
df
})
output$mymap <- renderLeaflet({ req(input$input1)
leaflet() %>% addTiles() %>% setView(lng = -100.94, lat = 38.94 , zoom
= 3.5) %>%
addProviderTiles(providers$Esri.NatGeoWorldMap) %>%
addMarkers(lng=react()$longitude, lat=react()$latitude,
popup = paste(d$m_name)
)
})
}
run app
shinyApp(ui, server)
I've been playing around with this for days so any help is greatly appreciated!