2017-01-23 49 views
0

手頭的任務很簡單 - 我希望能夠在Shiny應用中自定義我的Leaflet彈出窗口的CSS樣式。我試圖結合thisthis示例的解決方案無濟於事。如何在Shiny/R中創建自定義傳單彈出樣式

使用上述兩種連接解決方​​案,這裏是一些(失敗)的示例代碼:

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文件看起來是這樣的,並保存在文件夾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文件的路徑是問題。當我按原樣運行此代碼時,出現以下錯誤:

Warning in file(con, "r") : file("") only supports open = "w+" and open = "w+b": using the former

任何解決方案如何使其工作?

+1

你正在引用你的CSS錯誤的方式。看看這裏:https://shiny.rstudio.com/articles/css.html如果你只是改變標籤$頭爲'theme =「style.css」'它將工作 –

回答

1

Icaro Bombonato帶我到解決方案!而不是tags$head(includeCSS(system.file('www', 'style.css', package = 'myPackage'))),,UI中的所有必需項目是includeCSS("style.css")style.css文件也放在我的主Shiny目錄中,而不是www文件夾中。