以各种格式导出/下载具有光泽的传单地图?

时间:2019-01-10 15:23:14

标签: r dictionary download shiny leaflet

我创建了一个闪亮的仪表板来分析芝加哥的犯罪情况。因此,我还制作了一份芝加哥单张地图,从中可以根据标记查看在芝加哥哪个地区发生了多少犯罪。我有三个过滤器小部件(日期,犯罪类型和位置)。基于这3个小部件,用户可以玩耍,每次使用选定的输入重新绘制地图时。一切工作正常且良好,我只想添加一个“下载”部分,可以将带有标记的当前图导出为其他格式(png,pdf ...)。我的仪表盘看起来像这样:

Dashboard - Map Page

如您所见,我想给用户选择他想要的导出格式。我尝试了一些代码,但没有成功。

我的用户界面:

tabItem(tabName = "map",

      fluidRow(

        column(width = 9,
        # Main plot
        box(
          title = "Chicago Map", 
          status = "danger", 
          solidHeader = TRUE,
          width = NULL,
          height = NULL,
          #tags$style(type = "text/css", "#map {height: calc(100vh - 80px) !important;}"),
          leafletOutput("map",height = "95vh")
        )),

        column(width = 3,
        box(
          title = "Date", 
          status = "primary", 
          solidHeader = TRUE,
          width = NULL,
          #height = 142,
          sliderInput("mapYear", label = "Select Year", min = 2001, max = 2016, step = 1, sep = '', value = c(2001,2016))
        ),

        box(
          title = "Crime Type", 
          status = "primary", 
          solidHeader = TRUE,
          width = NULL,
          selectInput("mapCrimeType", label= "Select Crime Type", choices = unique(cc$Primary.Type), multiple = TRUE)
        ),

        box(
          title = "Location", 
          status = "primary", 
          solidHeader = TRUE,
          width = NULL,
          selectInput("mapLocation", label= "Select Location", choices = unique(cc$Location.Description), multiple = TRUE)
        ),

        box(
          title = "Download", 
          status = "success", 
          solidHeader = TRUE,
          width = NULL,
          radioButtons("mapFormat", "Document format", c("PNG"="png", "EPS"="eps", "PDF"="pdf"), inline = TRUE, selected = "png"),
          downloadButton("mapDownload")
        )
      )
    )
  ),

我的服务器是这样的:

  ### Draw Map ###
  output$map = renderLeaflet({
    m <- leaflet() %>% 
      addProviderTiles(providers$Esri.WorldStreetMap) %>% 
      setView(lng = -87.623177, lat = 41.881832, zoom=11)
  }) 

  reactMap = reactive({
    cc %>%
      filter(Primary.Type %in% input$mapCrimeType &
               Location.Description %in% input$mapLocation &
               Year2 %in% cbind(input$mapYear[1],input$mapYear[2]))
  })

  observe({
    proxy = leafletProxy("map", data = reactMap()) %>%
      clearMarkers() %>%
      clearMarkerClusters() %>%
      addCircleMarkers(clusterOptions = markerClusterOptions(),
                       lng =~ Longitude, lat =~ Latitude, radius = 5, group = 'Cluster', 
                       popup =~ paste('<b><font color="Black">', 'Crime Information', 
                                      '</font></b><br/>', 'Crime Type:', Primary.Type,'<br/>',
                                      'Date:', Date,'<br/>', #'Time:', Time,'<br/>',
                                      'Location:', Location.Description,'<br/>', 'Block:', Block, '<br/>', 'Arrest:', Arrest, '<br/>'))
  })  

  fnMap <- reactive({paste(input$mapCrimeType,input$mapLocation,sep = ".")})
  doMap <- reactive({input$mapFormat})

  # Download current plot
  output$mapDownload <- downloadHandler(
    filename = fnMap,
    content = function(file) {
      mapshot(m, file)
    }
  )

有人有什么想法或建议吗?我很高兴解决这个问题。提前非常感谢!

更新:有人知道如何解决我的代码吗?其他有类似问题的帖子对我不起作用。

0 个答案:

没有答案