【问题标题】:How to create custom leaflet popup style in Shiny/R如何在 Shiny/R 中创建自定义传单弹出样式
【发布时间】: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": 使用前者

任何解决方案如何让它工作?

【问题讨论】:

标签: javascript css r shiny leaflet


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-03-22
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    相关资源
    最近更新 更多