如何在 rmarkdown 单元格和闪亮中更改 css?
How to change css in rmarkdown cell & shiny?
我在 r
和创建 传单图 方面相对较新,为此我需要 白色背景 而不是 灰色.
我遇到了这个 SO post 同样: 并尝试过:
剧情代码:
daily_leaflet_plt <- ind_states %>% leaflet(options = leafletOptions(zoomControl = FALSE,
dragging = FALSE,
minZoom = 3,
style = list(
"background-color" = "white"
)
)) %>%
addPolygons(
label = label_daily,
labelOptions = labelOptions(
opacity = .6,
style = list(
"color" = "white",
"background-color" = "black",
"font-size" = "15px",
"border-color" = "rgba(0,0,0,0.5)"
)
),
stroke = TRUE,
color = "white",
dashArray = "3",
weight = .2,
smoothFactor = .5,
opacity = 1,
fillOpacity = 0.5,
fillColor = ~ pal_daily(Daily_confirmed),
highlightOptions = highlightOptions(weight = .5,
fillOpacity = 1,
bringToFront = TRUE)) %>%
addLegend(position = "bottomleft",
pal = pal_daily,
values = ~ ind_states$Daily_confirmed,
title = "Daily Confirmed Cases",
opacity = 0.7)
css 根据 SO post:
```{r results="daily_leaflet_plt"}
cat("
<style>
.leaflet-container {
background: #FFF;
}
</style>
")
```
但这不起作用,我怎样才能在 rmarkdown 和 shiny 中的传单 plt 中获得白色背景 space,因为最终我将在 shiny 中使用它。
我也在另一个 SO post 中提出了这个问题,但措辞不同且仍未得到答复:How to change color of leaflet map around the polygon shape in r?
我认为您的 CSS 选择器是正确的,但我个人认为以典型的 Shiny 方式指定它更容易,即
library(shiny)
library(leaflet)
ui <- fluidPage(
tags$head(tags$style(HTML(".leaflet-container {background: none;}")))
leafletOutput("map")
)
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet(quakes) %>%
addTiles()
})
}
shinyApp(ui, server)
对于 R markdown,您可以像嵌入 R 代码块一样嵌入 CSS 代码块,例如,
```{css, echo = FALSE}
.leaflet-container {
background: none;
}
```
```{r}
library(leaflet)
leaflet(quakes) %>%
addTiles()
```
我不确定,但我猜“结果”部分是错误的。
来源:Source of image "Rmarkdown Reference"
我认为你应该使用 results = 'asis'
我在 r
和创建 传单图 方面相对较新,为此我需要 白色背景 而不是 灰色.
我遇到了这个 SO post 同样:
剧情代码:
daily_leaflet_plt <- ind_states %>% leaflet(options = leafletOptions(zoomControl = FALSE,
dragging = FALSE,
minZoom = 3,
style = list(
"background-color" = "white"
)
)) %>%
addPolygons(
label = label_daily,
labelOptions = labelOptions(
opacity = .6,
style = list(
"color" = "white",
"background-color" = "black",
"font-size" = "15px",
"border-color" = "rgba(0,0,0,0.5)"
)
),
stroke = TRUE,
color = "white",
dashArray = "3",
weight = .2,
smoothFactor = .5,
opacity = 1,
fillOpacity = 0.5,
fillColor = ~ pal_daily(Daily_confirmed),
highlightOptions = highlightOptions(weight = .5,
fillOpacity = 1,
bringToFront = TRUE)) %>%
addLegend(position = "bottomleft",
pal = pal_daily,
values = ~ ind_states$Daily_confirmed,
title = "Daily Confirmed Cases",
opacity = 0.7)
css 根据 SO post:
```{r results="daily_leaflet_plt"}
cat("
<style>
.leaflet-container {
background: #FFF;
}
</style>
")
```
但这不起作用,我怎样才能在 rmarkdown 和 shiny 中的传单 plt 中获得白色背景 space,因为最终我将在 shiny 中使用它。
我也在另一个 SO post 中提出了这个问题,但措辞不同且仍未得到答复:How to change color of leaflet map around the polygon shape in r?
我认为您的 CSS 选择器是正确的,但我个人认为以典型的 Shiny 方式指定它更容易,即
library(shiny)
library(leaflet)
ui <- fluidPage(
tags$head(tags$style(HTML(".leaflet-container {background: none;}")))
leafletOutput("map")
)
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet(quakes) %>%
addTiles()
})
}
shinyApp(ui, server)
对于 R markdown,您可以像嵌入 R 代码块一样嵌入 CSS 代码块,例如,
```{css, echo = FALSE}
.leaflet-container {
background: none;
}
```
```{r}
library(leaflet)
leaflet(quakes) %>%
addTiles()
```
我不确定,但我猜“结果”部分是错误的。
来源:Source of image "Rmarkdown Reference"
我认为你应该使用 results = 'asis'