2016-07-05 78 views
6

当我想使用labelscolors参数和addLegend()函数在shinyApp内时,图例将以阶梯形式显示,如下所示。 但是,如果我只在shinyApp以外的地方渲染地图leaflet,则标签会正确显示为内嵌。
我看过this post同样的问题,但他们没有可再生的例子,所以我决定发布我自己的问题。图例标签在标签和颜色上使用标签和颜色时不能在内容中显示

  • 错误显示(发亮仪表盘)

​​

  • 正确的显示(小叶独立)

correctDisplay

我由reproductible示例:

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

回答

4

它可能发生的原因之一是当网页被放大时,即缩放级别超过100%。 确保您没有放大。按键盘上的Control + 0将缩放比例重置为100%。另外,如果问题仍然存在,请尝试使用其他网络浏览器。

自从我的浏览器放大(> 100%)以来,我有同样的愚蠢问题。

4

我有同样的问题。在我的情况下,调整图例的CSS解决了问题:

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