Shiny一次渲染一个响应式rCharts传单图,但是如果更改输入变量,则为空白 [英] Shiny renders a responsive rCharts leaflet map once, but is blank if you change the input variable
问题描述
我正在制作一个Shiny App,它会根据您选择的公交路线生成一张传单(rCharts)地图.乍一看,所有内容都能完美呈现,但是如果您更改路线编号,则会显示一个空白地图(甚至不包括图块).这并非特定于路线号.例如,我可以选择任何路径编号来成功生成第一个图,而无论路径编号如何,第二个图都为空白.
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
推荐答案
诀窍是删除map3$set(dom = 'map')
.问题解决了!
The trick is to remove map3$set(dom = 'map')
. Problem solved!
这篇关于Shiny一次渲染一个响应式rCharts传单图,但是如果更改输入变量,则为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!