我在让 Shiny 中的传单 map 全屏显示时遇到问题。虽然我显然可以手动将 map 的宽度和高度设置为我的屏幕尺寸,但我希望 map 能够适应它所显示的任何屏幕尺寸。
如何自动调整 map 的大小?
这是我迄今为止一直在尝试的代码。然而不幸的是,这并不能正确调整高度。
library(shiny)
library(leaflet)
location=c(46.52433,10.12633)
ui <- fluidPage(
tags$head(tags$style(HTML("#map {height:100%, width:100%;}"))),
leafletOutput("map")
)
server <- function(input, output, session) {
output$map = renderLeaflet({
leaflet() %>% addTiles() %>% setView(lat = location[1],lng = location[2],zoom = 10) %>%
addMarkers(lat = location[1],lng = location[2],popup = "Test") })
}
shinyApp(ui, server)
任何帮助将不胜感激,谢谢!
最佳答案
尝试将 width = "100%", height = "100%"
添加到 leafletOutput
并使用 fillPage()
,如下所示:
library(shiny)
library(leaflet)
location=c(46.52433,10.12633)
ui <- fillPage(
tags$style(type = "text/css", "html, body {width:100%; height:100%}"),
leafletOutput("map", width = "100%", height = "100%")
)
server <- function(input, output, session) {
output$map = renderLeaflet({
leaflet() %>% addTiles() %>% setView(lat = location[1],lng =
location[2],zoom = 10) %>%
addMarkers(lat = location[1], lng = location[2],popup = "Test") })
}
shinyApp(ui, server)
关于css - 在 R Shiny 中使 Leaflet Map 全屏显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61341817/