在传单中的传单地图中使用标签和颜色时,图例标签不显示内联

Chr*_* D. 6 r leaflet shinydashboard

当我想使用labels和图例中的功能colors参数显示在楼梯中时,如下所示.但是,如果我只使用标签外部的地图渲染,则内联正确显示. 我已经看到这个帖子有同样的问题,但他们不是可复制的例子所以我决定发表我自己的问题.addLegend()shinyAppleafletshinyApp

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

wrongDisplay

  • 正确显示(单张独立)

correctDisplay

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

# ----- 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)
Run Code Online (Sandbox Code Playgroud)

Ada*_*dam 6

我有同样的问题.在我的例子中,调整图例的CSS解决了这个问题:

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