Shiny renders a responsive rCharts leaflet map once, but is blank if you change the input variable

 ̄綄美尐妖づ 提交于 2019-12-09 23:47:50

问题


I am producing a Shiny App that produces a leaflet (rCharts) map depending on which bus route you pick. Everything renders perfectly at first glimpse, but if you change the route number, an empty map appears (not even a tilelayer). This isn't specific to the route number. For example, I can pick any route number to produce the first plot successfully, whereas the second plot, regardless of route number, is blank.

Has anyone come across this before? Is there a workaround?

Here is a simple example.

ui.R:

library(shiny)
library(rCharts)

shinyUI(fluidPage(
  titlePanel("Responsive Leaflet Map using rCharts"),

  sidebarLayout(
    sidebarPanel( "",
                  selectInput(
                    'route', 'Pick a bus route:',
                    choices = as.character(c("232","229"),
                                           selectize = FALSE)      
                  )
                  ),
    mainPanel("",
              chartOutput('map', 'leaflet')
              )
  )
))

server.R:

library(shiny)
library(rCharts)
library(RJSONIO)
library(rgdal)

shinyServer(function(input, output) {
  output$map <- renderMap({
    filename <- paste('json/',input$route,'.geojson',sep='')
    json <- fromJSON(file = filename)

    map3 <- Leaflet$new()
    map3$tileLayer(provide='Esri.WorldTopoMap')
    map3$setView(c(49.2494,-122.9797), zoom = 10)
    map3$set(dom = 'map')
    map3$fullScreen(TRUE)
    map3$geoJson(
      json,
      style = "#!
  {color: '#c93312'}!#")
    map3
  })
})

Thanks so much for any help you are able to provide.

C


回答1:


The trick is to remove map3$set(dom = 'map'). Problem solved!



来源:https://stackoverflow.com/questions/29189513/shiny-renders-a-responsive-rcharts-leaflet-map-once-but-is-blank-if-you-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!