How to change css in rmarkdown cell amp; shiny?(如何更改 rmarkdown 单元格中的 css amp;闪亮的?)
问题描述
我在 r
中相对较新,并创建 传单图 我需要 白色背景 而不是 灰色>.
I am relatively new in r
and creating leaflet plot for which I need a white background instead of grey.
我遇到了同样的 SO 帖子:blank, 传单地图的白色背景 &试过了:
I came across this SO post for same: blank, white background for leaflet map & tried:
剧情代码:
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)
按照 SO 帖子的 css:
```{r results="daily_leaflet_plt"}
cat("
<style>
.leaflet-container {
background: #FFF;
}
</style>
")
```
但这不起作用,如何在 rmarkdown & 中的传单 plt 中获得白色背景空间闪亮,最终我将在闪亮中使用它.
But this doesn't work, How can I get white background space in leaflet plt in rmarkdown & shiny as eventually I will be using this in shiny.
我也在另一篇 SO 帖子中提出了这一点,该帖子的措辞不同 &仍未得到答复:如何更改r中多边形形状周围的传单地图颜色?
I have also raised this in another SO post which is phrased differently & remains unanswered: How to change color of leaflet map around the polygon shape in r?
推荐答案
我认为您的 CSS 选择器是正确的,但我个人认为以典型的 Shiny 方式指定它更容易,即,
I think your CSS selector is correct, but I'd personally find it easier to just specify that in the typical Shiny way, i.e.,
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 代码块,例如,
For R markdown, you can embed a CSS code chunk as you would an R code chunk, e.g.,
```{css, echo = FALSE}
.leaflet-container {
background: none;
}
```
```{r}
library(leaflet)
leaflet(quakes) %>%
addTiles()
```
这篇关于如何更改 rmarkdown 单元格中的 css &闪亮的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何更改 rmarkdown 单元格中的 css &闪亮的?


- addEventListener 在 IE 11 中不起作用 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 400或500级别的HTTP响应 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01