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 &闪亮的?
基础教程推荐
- 直接将值设置为滑块 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01