【发布时间】:2019-02-12 02:34:46
【问题描述】:
我有一个闪亮的应用程序,它显示传单包中的地图。 我有兴趣将闪亮应用程序中的地图保存为 PNG 文件或 HTML 文件。在本地运行并使用以下代码在浏览器上打开闪亮的应用程序时,我设法将其保存为 PNG 文件:
library(shiny)
library(leaflet)
library( mapview)
ui <- fluidPage(
leafletOutput(outputId = "eiffelmap")
, downloadButton(outputId = "savemap")
)
server <- function(input, output, server){
name <- 'EIFFEL TOWER'
longitude <- 2.2945
latitude <- 48.8583
location <- data.frame(name,longitude,latitude)
icon.pop <- awesomeIcons(icon = 'thumb-tack',
markerColor = 'blue',
library = 'fa',
iconColor = 'black')
map <- reactive({
name <- 'EIFFEL TOWER'
longitude <- 2.2945
latitude <- 48.8583
location <- data.frame(name,longitude,latitude)
icon.pop <- awesomeIcons(icon = 'thumb-tack',
markerColor = 'blue',
library = 'fa',
iconColor = 'black')
leaflet(location) %>%
addProviderTiles(providers$Stamen.TonerLite,
options = providerTileOptions(noWrap = TRUE)
) %>%
addAwesomeMarkers(~longitude, ~latitude, label = ~name, icon=icon.pop)
})
output$eiffelmap <- renderLeaflet({
map()
})
output$savemap <- downloadHandler(
filename = "eiffelmap.png",
content = function(file){
mapshot(
x = map()
, file = file
)
}
)
}
shinyApp(ui, server)
我的问题是为什么当应用程序托管在 shiny.io 上时下载不起作用,但在浏览器上本地打开时却可以下载?我的代码有什么问题? 还有关于如何将传单地图保存为可以放大和缩小的交互式 HTML 的任何见解? 非常欢迎和赞赏任何见解或帮助。
【问题讨论】: