【问题标题】:leaflet in R-shiny: 100% height of leaflet mapR-shiny 中的传单:传单地图的 100% 高度
【发布时间】:2017-02-08 23:34:00
【问题描述】:

我正在尝试构建一个显示传单地图的应用程序。使用该应用程序的人大多是通过移动设备进行的——因此在整个屏幕上提供地图会很方便。 您可以在此处查看该应用程序:https://js1984.shinyapps.io/stackoverflow/

它适用于 leafletOutput("mymap", width = "100%") 的宽度,但是我无法将高度设置为 leafletOutput("mymap", width = "100%", height = "100%"):当我运行应用程序时地图将消失...将高度设置为固定值可以正常工作,但不是您可以想象的选项。

到目前为止我发现的所有解决方案都不适合我:比如在 CSS 中设置 height: 100%:

html, body, #mymap {
   height:100%;
   width:100%;
   padding:0px;
   margin:0px;
} 

应用的 UI 部分如下所示:

 ui <- navbarPage(title = "test",
             collapsible = T,
             position= "static-top",
             inverse = T,
             #####################################
             # the tab panel that includes the MAP
             #####################################
             tabPanel("Map",
             includeCSS(path="www/bootstrap.css"),
                      leafletOutput("mymap", width =  "100%")
             ),
             #####################################
             # other tab panels
             #####################################
             tabPanel("Fri",
                      fluidRow(
                        includeCSS(path="www/bootstrap.css"),
                        column(6,
                               offset = 3,
                               wellPanel(
                                 checkboxGroupInput("freitag",
                                                    h3("Freitag"),
                                                    list_fr,
                                                    selected = 1
                                 )
                               )
                        )
                      )
             ),
             tabPanel("Sat",
                      fluidRow(
                        column(6,
                               offset = 3,
                               wellPanel(
                                 checkboxGroupInput("samstag",
                                                    h3("Samstag"),
                                                    list_sa
                                 )
                               )
                        )
                      )
             ),
             tabPanel("Sun",
                      fluidRow(
                        column(6,
                               offset = 3,
                               wellPanel(
                                 checkboxGroupInput("sonntag",
                                                    h3("Sonntag"),
                                                    list_so
                                 )
                               )
                        )
                      )
             ),
             tabPanel("Mon",
                      fluidRow(
                        column(6,
                               offset = 3,
                               wellPanel(
                                 checkboxGroupInput("montag",
                                                    h3("Montag"),
                                                    list_mo
                                 )
                               )
                        )
                      )
             ),
             tabPanel("Tues",
                      fluidRow(
                        column(6,
                               offset = 3,
                               wellPanel(
                                 checkboxGroupInput("dienstag",
                                                    h3("Dienstag"),
                                                    list_di
                                 )
                               )
                        )
                      )
             )
)

【问题讨论】:

  • 据我所知,不可能将两个属性(高度和宽度)都设置为 %。
  • 其实可以,在Superzip中实现。但是,我也不知道是怎么回事。
  • 但无论如何,这里是solution

标签: r shiny leaflet


【解决方案1】:

正如 Dogan Askan(谢谢!)在 this comment 中指出的那样,使用 calc() 和窗口高度的解决方案对我有用。 See this answer 获取更详细的示例。

【讨论】:

    【解决方案2】:

    请参阅此解决方案。它将 css 应用于 container-fluid 类,这可能对其他选项卡不利。...adjust.css 进入 www 文件夹。基本思路取自here

    应用也在这个link

    ui.R

         library(shiny)
        library(leaflet)
    
        shinyUI(tagList(
                tags$head(
                        HTML("<link rel='stylesheet' type='text/css' href='adjust.css'>"),
                        HTML("<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />")
                ),
                navbarPage(title = "test",
                           collapsible = T,
                           position= "static-top",
                           inverse = T,
                           #####################################
                           # the tab panel that includes the MAP
                           #####################################
    
                           tabPanel("Map",
                                    #tags$div(id="map",     
                                             leafletOutput("mymap")
                                    #)
                           ),
                           #####################################
                           # other tab panels
                           #####################################
                           tabPanel("Fri",
                                    fluidRow(
    
                                            column(6,
                                                   offset = 3,
                                                   wellPanel(
                                                           checkboxGroupInput("freitag",
                                                                              h3("Freitag"),
                                                                              c("1", "2", "3"),
                                                                              selected = 1
                                                           )
                                                   )
                                            )
                                    )
                           ),
                           tabPanel("Sat",
                                    fluidRow(
                                            column(6,
                                                   offset = 3,
                                                   wellPanel(
                                                           checkboxGroupInput("samstag",
                                                                              h3("Samstag"),
                                                                              c("1", "2", "3")
                                                           )
                                                   )
                                            )
                                    )
                           ),
                           tabPanel("Sun",
                                    fluidRow(
                                            column(6,
                                                   offset = 3,
                                                   wellPanel(
                                                           checkboxGroupInput("sonntag",
                                                                              h3("Sonntag"),
                                                                              c("1", "2", "3")
                                                           )
                                                   )
                                            )
                                    )
                           ),
                           tabPanel("Mon",
                                    fluidRow(
                                            column(6,
                                                   offset = 3,
                                                   wellPanel(
                                                           checkboxGroupInput("montag",
                                                                              h3("Montag"),
                                                                              c("1", "2", "3")
                                                           )
                                                   )
                                            )
                                    )
                           ),
                           tabPanel("Tues",
                                    fluidRow(
                                            column(6,
                                                   offset = 3,
                                                   wellPanel(
                                                           checkboxGroupInput("dienstag",
                                                                              h3("Dienstag"),
                                                                              c("1", "2", "3")
                                                           )
                                                   )
                                            )
                                    )
                           )
                )  
        ))
    

    服务器.R

        library(shiny)
        library(leaflet)
    
        shinyServer(function(input, output) {
                output$mymap <- renderLeaflet({
                        points <- cbind(rnorm(40) * 2 + 13, rnorm(40) + 48)
    
                        leaflet() %>%
                                addProviderTiles("Stamen.TonerLite",
                                                 options = providerTileOptions(noWrap = TRUE)
                                ) %>%
                                addMarkers(data = points)
                })
        })
    

    调整.css

    body, .container-fluid {
            padding: 0;
            margin: 0;
        }
    
        html, body, #mymap {
    
                height: 100%;
                width: 100%;
        }
    

    【讨论】:

      猜你喜欢
      • 2015-06-28
      • 2020-06-20
      • 1970-01-01
      • 2016-05-24
      • 2017-07-29
      • 2021-06-18
      • 2021-08-15
      • 2021-09-22
      • 2015-12-30
      相关资源
      最近更新 更多