Reputation: 489
still learning how to use Shiny/R, sorry if the answer is obvious trying to cast on the map various layers based on selectize choices (multiple) So i got:
selectizeInput('bays', 'Select rough bay outlines',
choices = list("Residents" = "residents", `Pay to park` = "ptp",
"Shared use" = "shared"), multiple = TRUE)
Every equivalent is a geojson
file that should be used for the map (here "residents", but of course it populates with a selected option from the selectize input):
topoData <- readLines("residents.geojson", warn = FALSE)
%>% paste(collapse = "\n")
leafletProxy("mymap") %>%
addPolylines(topodata)
how can i construct the observeEvent(input$bays,...)
so every choice triggers the action above (with the right geojson file of course)? I can do it for a single choice but a multiple choice might call for another way. And would it be more effective to use a submit
button or react to actions? Please note that it can be either adding or removing value from the selectize list? And finally there is a cool gadget in selectize - plugin "remove_button" - adding the entries with a little marker to remove the item - i have seen it for javascript but not for shiny - is it possible somehow?
$('#input-tags3').selectize({
plugins: ['remove_button'],
delimiter: ',',
persist: false,
create: function(input) {
return {
value: input,
text: input
}
}
});
Upvotes: 2
Views: 962
Reputation: 5779
You do not want an observeEvent
but a reactive
. Something like this should work:
# server
topoData <- reactive(
paste(
lapply(
paste0(input$bays,".geojson"), function(geojson) {
readLines(geojson)
}
),collapse="\n")
)
leafletProxy %>% addPolyLines(topoData())
input$bays
is a vector of the selected geojson files, and it is reactive so as people change the selectize input the value updates in the server inside of reactive statements (and observe statements).
topoData
is a reactive the returns the geojson files that are selected. If I understand correctly you just went to paste the different files on top of each into a single character. The leafletProxy
may have to go inside an observe
, I'm not sure.
Upvotes: 0