3

is it possible to create an interactive html document without using shiny, in which I can select one single marker on a map (leaflet htmlwidget), so the corresponding observation is highlighted/selected in another htmlwidget?

What I have so far in a flexdashboard:

  • a leaflet map and
  • a d3scatter plot
  • using the same SharedData utilizing crosstalk

Now the leaflet map already offers me a selection tool with which I can draw a rectangle to select multiple points - these get highlighted in the scatterplot. The same works vise versa.

How can I choose only one marker/data point and get the same result? Alternatively I would like to use a table instead of a scatterplot. In the end I'd like to be able to getting any information I want in that box. (Could one idea be to use the leaflet popup - and edit the popup position that way that it appears next to the map instead of on top?)

I would like to avoid shiny and do it all html/JavaScript based so everyone I send the html to can see the dashboard without the necessity of having R.

Thank you!

MWE:

---
title: "Leaflet crosstalk"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(leaflet)
library(crosstalk)
```

Column {data-width=650}
-----------------------------------------------------------------------
### Map crosstalk

```{r leaflet crosstalk, echo=FALSE, message=FALSE, warning=FALSE}
#initialize crosstalking shared Data
shared.stations <- SharedData$new(quakes)

# initialize leaflet and add Tiles to see a map
leaflet(shared.stations) %>%
  addTiles() %>%
  addMarkers()

```

Column {data-width=350}
-----------------------------------------------------------------------
### scatter crosstalk

```{r}
library(d3scatter)
d3scatter(shared.stations, width = "100%", height = 400, ~depth, ~lat)
```
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Nele
  • 31
  • 5
  • You can always export the data (in CSV or JSON) and build an independent HMTL page from it. When things get really complicated (= outside common cases illustrated by the package maker), it's actually a hard work to implement directly from R. – Arthur Oct 06 '17 at 12:32
  • [Crosstalk's GitHub](https://github.com/rstudio/crosstalk) clearly states that "currently, [only] linked brushing and filtering" are implemented. – Arthur Oct 06 '17 at 12:35
  • Thanks for your comment. Since the data shown in the map will change quite often, I would like to avoid to export and edit the generated data. I figured since "linked brushing" is implemented and a selection of several point is working, that it should be possible to also only select single points. But I also understand that these tools are still quite young and under heavy development. May there be another solution to achieve an interactive document connecting locations on a map with data belonging to that datapoint? – Nele Oct 07 '17 at 16:39
  • I might have found a solution using `plotly` for the map instead of leaflet. However, I already ran into several problems: One is, that Rstudio is apparently not able to show `plot_geo` from plotly (e.g. only showing the interactive plotly buttons). This can be avoided via "show in new window" [link](https://github.com/ropensci/plotly/issues/1111). That is where I ran into another problem - firefox not showing the plotly plots at all. This can be resolved with this help: [link](https://github.com/ropensci/plotly/issues/483) I will post a working solution as soon as I can get it to work. – Nele Oct 13 '17 at 20:47

0 Answers0