Interactive Mapping Options


#1

Hi everyone,

I’ve just been asked to do an interactive map for someone on a fairly tight timeline, and I’m weighing up the best option to implement it. It’s going to be a list of regions (groups of countries), and when you click or hover on them a bunch of statistics are reported. The only tricky part is that we’d like to have a slider either on the map or on this info pane, whereby dragging it updates the statistics. All the numbers are pre-crunched.

None of this is too controversial, but we don’t want to run a Shiny app here: we’d like to be able to embed it on our own website as a fairly static affair and hopefully package it up to give to others. If it’s a choice between that and the slider, the portability wins out. So, really, it probably needs to be something we can export with htmltools.

The other options I’m familiar with are leaflet and plotly. The former I think is probably going to face the same problem (requires a Shiny server for the interactivity). The latter I’ve seen use interactivity with ggplotly, and I understand it does basic mapping (maybe no fancy map tiles like leaflet, but that’s an acceptable compromise).

Does anyone have any other ideas for doing this?


Best package for interactive graphs in Shiny
#2

The leaflet package does come with some standard interactivity - largely through toggles and radio buttons. You can also use htmlwidgets::saveWidgets to create a self-contained HTML file for the map. Although, depending on the level of detail in your map this may get a bit bulky.

What would the slider be changing - time, weights, or something else entirely? If the goal is to change the underlying data to map, could accomplish the same via something that is already pre-packaged w/in the leaflet landscape?

I’m not sure how “into the weeds” you want to get, but this SO answer on how to add a time-dependency to a leaflet map might be a good thread to start tugging on. The answer is kinda JavaScript-lite, so depending on your comfort level there it may or may not make sense to go this route.


#3

Not a time dependency (sorry for the caginess—this is under embargo, so I’m not sure how much I can talk about it). Essentially four or five different scenarios, and we’d update an info pane (and possibly a fill or something) based on the selected scenario.

Yeah, I think we would probably use htmlwidgets::saveWidgets to export it out—unless we went the plotly route, in which case we could just host it with them.

If leaflet could do radio buttons, that could also work :smiley: I’d prefer a slider, but the important thing is that we Get It Out :stuck_out_tongue:


#4

leaflet can definitely do radio buttons. Here’s one example.

For more on leaflet interactivity options via showing/hiding group layers via toggle controls - this is a solid resource. Hope it helps!