如何更改 rmarkdown 单元格中的 css &闪亮的?

How to change css in rmarkdown cell amp; shiny?(如何更改 rmarkdown 单元格中的 css amp;闪亮的?)

本文介绍了如何更改 rmarkdown 单元格中的 css &闪亮的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 &amp;闪亮的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何更改 rmarkdown 单元格中的 css &amp;闪亮的?

基础教程推荐