【问题标题】:legend labels not displaying inline when using labels and colors in leaflet map on shiny在闪亮的传单地图中使用标签和颜色时,图例标签不显示内联
【发布时间】:2016-07-05 07:44:13
【问题描述】:

当我想在 shinyApp 中使用 labelscolors 参数和 addLegend() 函数时,图例显示在楼梯中,如下所示。 但是,如果我仅在 shinyApp 之外使用 leaflet 渲染地图,则标签将正确内联显示。
我见过this post 有同样的问题,但他们不是可复制的例子,所以我决定发布我自己的问题。

  • 显示错误(闪亮的仪表板)

  • 正确显示(单张独立)

我做了一个可复制的例子:

# ----- Load and install missing packages
packages<-c("shiny","shinydashboard","leaflet")
new.packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
lapply(packages, require, character.only = TRUE)
rm(list = c("new.packages","packages"))

# ----- Reproductible Example

# ----- UI
header <- dashboardHeader(title = "Repoductible Example")
sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("map", tabName = "map", icon = icon("globe",lib="font-awesome"))
  )
)
body <- dashboardBody(
  tabItems(
    tabItem(tabName= "map",
            column(width=12,
                   leafletOutput("mapExmpl", width="100%",height=600)))
  )
)

ui <- dashboardPage(header, sidebar, body,skin="blue")

# ----- Server
server <- function(input, output) {
  labels=c("Label1","Label2","Label3","Label4","Label5")
  colors<-c(rgb(243,87,26,maxColorValue=256)
            ,rgb(225,205,19,maxColorValue=256)
            ,rgb(62,3,79,maxColorValue=256)
            ,rgb(17,126,147,maxColorValue = 256)
            ,rgb(61,255,80,maxColorValue=256))
  output$mapExmpl<-renderLeaflet({
    leaflet()%>%addTiles(
    )%>%
      addLegend("bottomright", colors = colors, labels =labels ,
                title = "Typo",
                opacity = 1
      )
  })


}

shinyApp(ui,server)

【问题讨论】:

    标签: r leaflet shinydashboard


    【解决方案1】:

    我遇到了同样的问题。就我而言,调整图例的 CSS 解决了这个问题:

    ui <- bootstrapPage( 
      tags$style(type="text/css", "div.info.legend.leaflet-control br {clear: both;}"),
    ...
    )
    

    【讨论】:

      【解决方案2】:

      可能发生这种情况的原因之一是网页放大时,即缩放级别超过 100%。 确保您没有放大。按键盘上的Control + 0 将缩放重置为 100%。此外,如果问题仍然存在,请尝试使用其他网络浏览器。

      自从我的浏览器放大 (>100%) 后,我遇到了同样愚蠢的问题。

      【讨论】:

        猜你喜欢
        • 2020-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-13
        • 2021-10-04
        相关资源
        最近更新 更多