【发布时间】:2017-06-08 09:57:34
【问题描述】:
手头的任务很简单——我希望能够在 Shiny 应用程序中自定义我的 Leaflet 弹出窗口的 CSS 样式。我尝试将 this 和 this 示例中的解决方案结合起来,但无济于事。
使用上述两个链接的解决方案,这里是一些(失败的)示例代码:
library(shiny)
library(leaflet)
shinyApp(
ui <- fluidPage(
tags$head(includeCSS(system.file('www', 'style.css', package = 'myPackage'))),
leafletOutput("map", width = "100%", height = "800")
), #END UI
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
addCircles(lng = -80, lat = 30, radius = 100, popup = as.character("Test"))
}) #END RENDERLEAFLET
}
)
style.css 文件如下所示,保存在我的 Shiny 应用目录内的 www 文件夹中:
<style>
.custom-popup .leaflet-popup-content-wrapper {
background: #DB0925;
color:#fff;
font-size:16px;
line-height:24px;
}
.custom-popup .leaflet-popup-content-wrapper a {
color:rgba(255,255,255,0.5);
}
.custom-popup .leaflet-popup-tip-container {
width:30px;
height:15px;
}
.custom-popup .leaflet-popup-tip {
border-left:15px solid transparent;
border-right:15px solid transparent;
border-top:15px solid #2c3e50;
}
</style>
<div class='custom-popup' id='map'></div>
我怀疑我的 css 文件的路径是问题所在。当我按原样运行此代码时,出现以下错误:
file(con, "r") 中的警告:file("") 仅支持 open = "w+" 和 open = "w+b": 使用前者
任何解决方案如何让它工作?
【问题讨论】:
-
您以错误的方式引用您的 css。看看这里:shiny.rstudio.com/articles/css.html 如果您只是将标签$head 更改为
theme = "style.css",它将起作用
标签: javascript css r shiny leaflet