如何在Shiny/R中创建自定义传单弹出样式



手头的任务很简单——我希望能够在Shiny应用程序中自定义传单弹出窗口的CSS样式。我尝试将此示例和此示例的解决方案结合起来,但没有成功。

使用以上两种链接的解决方案,以下是一些(失败的)示例代码:

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文件的路径是问题所在。当我按原样运行此代码时,我会得到以下错误:

文件(con,"r")中的警告:文件(")仅支持open="w+"和open="w+b":使用以前的

有什么解决方案可以让它发挥作用吗?

Icaro Bombonato带领我找到了解决方案!所需的只是UI中的includeCSS("style.css"),而不是tags$head(includeCSS(system.file('www', 'style.css', package = 'myPackage'))),style.css文件也位于我的主Shiny目录中,而不是www文件夹中。

最新更新