如果我想在labels
内使用带有colors
功能的addLegend()
和shinyApp
参数,则会在楼梯中显示图例,如下所示。
但是,如果我仅使用leaflet
之外的shinyApp
呈现地图,则标签会正确显示内联。
我看到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)
答案 0 :(得分:6)
我遇到了同样的问题。在我的例子中,调整图例的CSS解决了问题:
ui <- bootstrapPage(
tags$style(type="text/css", "div.info.legend.leaflet-control br {clear: both;}"),
...
)
答案 1 :(得分:4)
可能发生的一个原因是当网页被放大时,即缩放级别大于100%。
确保没有放大。按键盘上的Control + 0
将缩放重置为100%。此外,如果问题仍然存在,请尝试使用其他网络浏览器。
自从我的浏览器放大(&gt; 100%)后,我遇到了同样的愚蠢问题。