传单图例项目未正确显示(对齐)为“有光泽" [英] Leaflet Legend Items Are Not Displayed (Aligned) Correctly in Shiny

查看:76
本文介绍了传单图例项目未正确显示(对齐)为“有光泽"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用闪亮的应用程序渲染一些传单地图,问题是地图的图例无法正确显示,并且图例项非常奇怪地对齐(图2).我在R Studio和Rstudio Viewer中创建了相同的地图,图例项对齐正确(图像1).
我尝试在闪亮的代码中使用CSS标记来自定义图例,但没有任何效果.

I am rendering some leaflet maps in my shiny app and the problem is that the legend of the map is not displayed correctly and legend items are aligned very weirdly (image 2). I create the same map in R studio and in the Rstudio Viewer, legend items alignment is correct (image 1).
I have tried using CSS tags in my shiny code to customize the legend, but nothing works.

这是示例代码,以显示如何渲染传单图(以及我尝试过的CSS标签示例).我不知道为什么这样显示项目.非常感谢您的帮助.

Here is sample code to show how I am rendering leaflet plot (and also the CSS tags examples I've tried). I dont know why the items are displayed like this. I would really appreciate your help on this.

...
tabPanel("plot", 
  tagList(
    tags$head(
      tags$style(
         ".leaflet .legend {width:200px; text-align: left;}",
         ".leaflet .legend i{float: left;}",
         ".leaflet .legend label{float:left; text-align: left;}"
       )
     )
  ),

  leafletOutput("leaflet_plot", width = 800, height = 550)
)
...

# code to create leaflet
output$leaflet_plot <- renderLeaflet({
  pal <- c("#F1F1F1", brewer.pal(5, "YlOrBr"))
  opts <- providerTileOptions(opacity = 0)
  map <- leaflet(shape_file) %>% addProviderTiles("CartoDB.PositronNoLabels", options = opts)
  map <- map %>% addPolygons(fillColor = ~colorFactor(pal, shape_file$var)(var)
  map <- map %>% addLegend("bottomleft", title = "Employment/Acre", pal = colorFactor(pal, NULL), values = ~var)
  map
})

谢谢,
灰烬

推荐答案

如果浏览器的缩放比例大于100%,则可能会发生这种情况. 查看此重复的帖子,其中包含可重复的示例.

This may happen if the zoom level of the browser is more than 100%. Look at this duplicate post that has a reproducible example.

这篇关于传单图例项目未正确显示(对齐)为“有光泽"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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