在闪亮的传单地图中使用标签和颜色时,图例标签未显示为内联 [英] legend labels not displaying inline when using labels and colors in leaflet map on shiny

查看:78
本文介绍了在闪亮的传单地图中使用标签和颜色时,图例标签未显示为内联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想在shinyApp中将labelscolors参数与addLegend()函数一起使用时,图例显示在楼梯中,如下所示. 但是,如果我仅使用shinyApp以外的leaflet渲染地图,则标签会正确内联显示.
我见过这篇文章,内容相同问题,但它们不是可复制的示例,所以我决定发布自己的问题.

When i want to use labels and colors parameters with addLegend() function inside a shinyAppthe legend is displayed in staircase as you can see below. But if i render the map only with leaflet outside of the shinyAppthe labels are correctly displayed inline.
I have seen this post with the same issue but their is no reproductible example so i decided to post my own question.

  • 错误的显示(发光的仪表板)

  • 正确显示(传单独立版)

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

I made a reproductible example :

# ----- 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)

推荐答案

我遇到了同样的问题.就我而言,调整图例的CSS可以解决问题:

I had the same problem. In my case, adjusting CSS of the legend solved the problem:

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

这篇关于在闪亮的传单地图中使用标签和颜色时,图例标签未显示为内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆