css - 在 R Shiny 中使 Leaflet Map 全屏显示

标签 css r shiny leaflet

我在让 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/

相关文章:

r - 从全局环境访问对象,这些对象直接传递给 ggplot 包装器中的函数

r - 在 Shiny 中使用带有反应式数据集的 dplyr 输入变量时出现问题

r - Shiny 的标签滚动条

html - 文本居中且图标左对齐

IE11 中的 HTML 选择菜单问题

CSS 可滚动百分比 div

r - googleUser.getAuthResponse().id_token 不返回 Shiny 的 id_token

html - 当鼠标移动到 UL LI 列表时,顶部悬停边框颜色切换为默认颜色

r - 如何为scale_alpha创建连续的图例(彩条样式)?

R生成带有空格的标签