我正在使用 R 组合传单对象和 dygraph。
特别是我希望一个 dygraph(理想情况下是任何 htmlwidget)显示为地图上点的弹出窗口。
下面是我大致尝试生成的代码。
理想情况下,当用户单击标记时,dygraph 应该出现在弹出窗口中。
# example dygraph
library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
dygraph(lungDeaths)
dd <- .Last.value
# example leaflet map
library(leaflet)
leaflet() %>%
addTiles() %>%
addMarkers(lng=174.768, lat=-36.852,
popup="The birthplace of R")
ll <- .Last.value
# I would like to be able to incorporate the dygraph as the popup,
# however the below doesn't work.
ll %>% addMarkers(lng=174.769, lat=-36.853,
popup=dd)
# the end goal is to have this combined in a shiny output
# below is a rough skeleton to add what I would expect to code
# in order to be able to add the dygraph into the popup
library(shiny)
library(leaflet)
library(dygraphs)
ui <- fluidPage(
leafletOutput("mymap")
)
server <- function(input, output, session) {
output$mymap <- renderLeaflet({
leaflet() %>%
addTiles() %>%
addMarkers(lng=174.768, lat=-36.852,
popup=dygraph(lungDeaths))
})
}
shinyApp(ui, server)