我想知道,在shiny R中,我们如何更改leaflet地图的大小。例如,考虑以下代码:
library(leaflet)
library(shiny)
app = shinyApp(
ui = fluidPage(
sidebarLayout(
sidebarPanel( sliderInput("obs",
"Number of observations:",
min = 0,
max = 1000,
value = 500)
),
mainPanel(
leafletOutput('myMap', width = "200%", height = 1400)
)
)
),
server = function(input, output) {
map = leaflet() %>% addTiles() %>% setView(-93.65, 42.0285, zoom = 17)
output$myMap = renderLeaflet(map)
}
)
if (interactive()) print(app)
要更改地图的大小,我可以在 UI 中更改宽度和高度参数。但是当我尝试在服务器中更改时,它并没有成功。
我不知道是否有任何方法可以通过服务器在 UI 中更改参数。我尝试了这种方法,但它并没有起作用。
library(leaflet)
library(shiny)
Height = 1000
app = shinyApp(
ui = fluidPage(
sidebarLayout(
sidebarPanel( sliderInput("Height",
"Height in Pixels:",
min = 100,
max = 2000,
value = 500)
),
mainPanel(
leafletOutput('myMap', width = "200%", height = Height)
)
)
),
server = function(input, output) {
Height <- reactive(input$Height)
map = leaflet() %>% addTiles() %>% setView(-93.65, 42.0285, zoom = 17)
output$myMap = renderLeaflet(map)
}
)
if (interactive()) print(app)
我只想知道如何使地图大小动态化,以便我可以控制它。非常感谢任何帮助。