8

リーフレット マップのスタイルを変更したいと考えています。

含めることは可能ですか

  • スタイル要素または
  • css ファイルへのカスタム パス

RまたはLeafletRのhtmlwidgetsを介して?

一番

4

1 に答える 1

14

質問にコードがまったくないため、回答は非常に困難です。答えてみます。CSSにカスタムを追加するには、2 つの方法がありますhtmlwidgetただし、非常に具体的にする!importantか、オーバーライドを使用する必要があることを前もって警告しますCSSleaflet.

簡単だが堅牢性に劣る

htmlwidgetsパッケージtagsから組み合わせることができます。htmltools

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
  ))
)

htmlDependency でより堅牢に

htmlDependency重複による競合を処理する を使用することもできます。

#  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
于 2016-03-03T14:44:53.753 に答える