是否可以在HTMLWidget中为R和/或传单包含自定义css?

是否可以在HTMLWidget中为R和/或传单包含自定义css?,r,leaflet,htmlwidgets,R,Leaflet,Htmlwidgets,我想对我的传单地图做一些样式上的更改 有可能包括 样式元素或 css文件的自定义路径 通过htmlwidgets for R或传单 最好的问题中没有任何代码,回答起来非常困难。我试着回答。有两种方法可以将自定义CSS添加到htmlwidget。我会提前提醒你,你需要非常具体,或者使用!重要信息覆盖,因为已经有相当多的文件自动添加到传单 简单但不太坚固 htmlwidgets可以与htmltools包中的tags组合使用 library(leaflet) library(htmltools)

我想对我的传单地图做一些样式上的更改

有可能包括

  • 样式元素或
  • css文件的自定义路径
通过htmlwidgets for R或传单


最好的

问题中没有任何代码,回答起来非常困难。我试着回答。有两种方法可以将自定义
CSS
添加到
htmlwidget
。我会提前提醒你,你需要非常具体,或者使用
!重要信息
覆盖,因为已经有相当多的文件自动添加到
传单

简单但不太坚固

htmlwidgets
可以与
htmltools
包中的
tags
组合使用

library(leaflet)
library(htmltools)

# example from ?leaflet
m = leaflet() %>% addTiles()

# there are two approaches to the custom css problem
#  1.  the easy but less robust way
browsable(
  tagList(list(
    tags$head(
      # you'll need to be very specific
      tags$style("p{font-size:200%;}")
      # could also use url
      #tags$link(href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css",rel="stylesheet")
    ),
    m
  ))
)
通过HTMLDependence更加健壮

您还可以使用
htmlDependence
,它将处理由重复项引起的冲突

#  2.  you can add dependencies to your leaflet map
#  this mechanism will smartly handle duplicates
#  but carries a little more overhead
str(m$dependencies)  # should be null to start
# 
m$dependencies <- list(
  htmlDependency(
    name = "font-awesome"
    ,version = "4.3.0"
    # if local file use file instead of href below
    #  with an absolute path
    ,src = c(href="http://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css")
    ,stylesheet = "font-awesome.min.css"
  )
)

m
#2。您可以向传单地图添加依赖项
#此机制将巧妙地处理重复项
#但是会有更多的开销
str(m$dependencies)#开始时应为null
# 

m$dependencies您是否有一点可复制的代码或自定义传单样式的示例?我想我有答案,但我不知道
htmltools
肯定会是您在这里的朋友,但是我们可以使用依赖项来探索其他一些选项。您是否在
rmarkdown
中使用?不,我不使用rmarkdown。我想在一个独立的网站上使用它。谢谢。正是我需要的。