trafficonese / leaflet.extras2

Extra functionality for leaflet R package.
https://trafficonese.github.io/leaflet.extras2/
GNU General Public License v3.0
85 stars 20 forks source link

Sidebar v2 working with crosstalk #41

Closed ccamara closed 2 years ago

ccamara commented 2 years ago

Apparently, sidebar v2 is only working with shiny (https://github.com/trafficonese/leaflet.extras2/blob/master/inst/examples/sidebar_app.R), but I am wondering if it would be possible to make it work with crosstalk (https://rstudio.github.io/crosstalk/), so it could be deployed without a need for a shiny server.

trafficonese commented 2 years ago

Hey @ccamara , unfortunately I havent worked too much with crosstalk so my knowledge about it is very limited, but isn't it supposed to connect htmlwidgets together? I am not sure how this plugin should be included with crosstalk, since the sidebar is just a placeholder for different inputs or outputs. Do you mean markdown maybe?

ccamara commented 2 years ago

Good question, @trafficonese . Yes, crosstalk is aimed at implementing cross-widget interactions (currently, linked brushing and filtering). I do not know how it relates to sidebar, but I was asking because reading from the documentation it seemed that it requires shiny for some kind of reactiveness (not sure if I understand why, though).

So, let me rephrase my question: is it possible to use sidebar v2 in rmarkdown (without shiny)? If so, how?

trafficonese commented 2 years ago

Apparently it is possible :)

I just pushed f0e009d which gets the correct map-id, so the sidebar is appended correctly.

Here is a little markdown with a leaflet sidebar:

---
title: "Rmarkdown HTML including Leaflet Sidebar"
output: html_document
---

Show "Leaflet Sidebar" within Rmarkdown.

```{r echo=F, include=TRUE}
library(shiny)
library(leaflet)
library(leaflet.extras2)
sidebar_tabs(id = "mysidebarid",
  list(icon("car"), icon("user")),
  sidebar_pane(
    title = "home", id = "home_id", icon = icon("home"),
    sliderInput("obs", "Number of observations:",
                min = 1, max = 32, value = 10)
  ),
  sidebar_pane(
    title = "profile", id = "profile_id", icon = icon("wrench"),
      textInput("caption", "Caption", "Data Summary")
  )
)
leaflet() %>%
  addTiles() %>%
  setView(lng = 5.0, lat = 51.0, zoom = 6) %>%
  addSidebar(id = "mysidebarid",
             options = list(position = "left"))
ccamara commented 2 years ago

Great, thanks! I will be playing with this to see if I can replace tooltips with information within the sidebar!