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

标签 r leaflet shinydashboard

当我想使用时 labelscolors参数与 addLegend() shinyApp 中的函数图例显示在楼梯中,如下所示。
但是如果我只用 leaflet 渲染 map 外shinyApp标签正确显示内联。
我见过this post有同样的问题,但他们不是可复制的例子,所以我决定发布我自己的问题。

  • 错误显示( Shiny 的仪表板)

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

    最佳答案

    我有同样的问题。就我而言,调整图例的 CSS 解决了问题:

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

    关于r - 在 Shiny 的传单 map 中使用标签和颜色时,图例标签不显示内联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38197890/

    相关文章:

    r - R 中的直方图 1 个 bin 仅用于零

    r - 在整个分隔符处分割,但不是分隔符的每个组成部分

    r - shiny:按下actionButton后应用shinycustomerloader

    javascript - 如何从以下内容中获取纬度和经度?

    R DT打包按钮下载文件不包含显示表

    css - 在dashboardBody Shinydashboard中使用CSS更改字体系列

    r - 线性模型和 dplyr - 更好的解决方案?

    r - 什么时候在 RStudio 中将数据存储在内存之外变得有益?

    r - 单击 map 后,ObserveEvent 不会打印出图层 ID

    javascript - 传单路由不显示路径