0
我正在使用R組合傳單對象和dygraph。將htmlwidget添加到傳單對象的彈出窗口中
特別是我想要一個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)
謝謝!對於大量的積分,你有沒有關於如何爲每個點獲取不同圖表的建議? –
嘗試傳遞圖表列表。參見'popupGraph'中的'### example:html -----'(最後一個例子)。雖然請注意,對於大量的點,這可能會變得非常緩慢且無法響應,因爲您正在將大量html代碼填充到一個頁面中。 – TimSalabim