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

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

问题描述

当我想将 labelscolors 参数与 shinyApp 图例中的 addLegend() 函数一起使用时如下所示,显示在楼梯中.但是,如果我仅使用 shinyApp 之外的 leaflet 渲染地图,则标签将正确显示为内联.
我已经看到

  • 正确显示(单张独立)

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

# ----- 加载和安装缺失的包包<-c("闪亮","闪亮仪表板","传单")new.packages <- packages[!(packages %in% installed.packages()[,"Package"])]如果(长度(new.packages)) install.packages(new.packages)lapply(包,需要,character.only = TRUE)rm(list = c("new.packages","packages"))# ----- 可复制的例子# ----- 用户界面header <-dashboardHeader(title = "Repoducible Example")侧边栏 <-dashboardSidebar(侧边栏菜单(menuItem("map", tabName = "map", icon = icon("globe",lib="font-awesome"))))正文 <-dashboardBody(选项卡项(tabItem(tabName="地图",列(宽度=12,LeafletOutput("mapExmpl", width="100%",height=600)))))ui <-dashboardPage(header, sidebar, body,skin="blue")#  -  - - 服务器服务器 <- 功能(输入,输出){标签=c("Label1","Label2","Label3","Label4","Label5")颜色<-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))输出$mapExmpl<-renderLeaflet({传单()%>%addTiles()%>%addLegend("bottomright", 颜色 = 颜色, 标签 =labels ,标题=错字",不透明度 = 1)})}闪亮应用(用户界面,服务器)

解决方案

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

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

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.

  • Wrong Display (shiny dashboard)

  • Correct Display (leaflet standalone)

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)

解决方案

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天全站免登陆