在R中修改传单弹出窗口 [英] Modifying Leaflet Popups in R

查看:109
本文介绍了在R中修改传单弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改R中传单弹出窗口的外观。

I want to modify the appearance of leaflet popups in R.

帮助文件指出 ... popupOptions()函数中的
传递给底层Javascript对象构造函数的额外选项。

The helpfile states that ... in the popupOptions() function takes "extra options passed to underlying Javascript object constructor."

此示例中,样式选项设置为可修改标记外观的CSS参数列表:

In this example, the style option is set to a list of CSS parameters that modify the appearance of markers:

  addMarkers(
    lng = -118.456554, lat = 34.075,
    label = "Label w/ custom CSS style",
    labelOptions = labelOptions(noHide = T, direction = "bottom",
      style = list(
        "color" = "red",
        "font-family" = "serif",
        "font-style" = "italic",
        "box-shadow" = "3px 3px rgba(0,0,0,0.25)",
        "font-size" = "12px",
        "border-color" = "rgba(0,0,0,0.5)"
      )))

但是ame方法似乎不适用于Popups,如以下最小示例所示:

However, the same approach does not seem to work with Popups, as this minimal working example demonstrates:

if (!require("pacman")) install.packages("pacman")
pacman::p_load(leaflet, eurostat, dplyr)

map <- get_eurostat_geospatial() %>% subset(., .$NUTS_ID == "AT11")

leaflet() %>%

  addPolygons(data = map , 
              group = map$NUTS_ID,
              fillColor = "grey",
              weight = 1,
              color = "black") %>%

  addPopups(lng = 16.3, lat = 47, popup = "Paint it black!",
            options = popupOptions(closeButton = FALSE,
                                   opacity = 0.5,
                                   style = list("background" = "black",
                                                "padding" = "2px",
                                                "border-radius" = "0px")))

某些网页解释了的使用Leaflet的javascript版本使用CSS自定义标签(例如此处)。关键似乎是编辑 .leaflet-popup-tip .leaflet-popup-content-wrapper 。但是如何在 R (不使用Shiny)中做到这一点?

Some webpages explain the customization of the labels with CSS using the javascript version of Leaflet (e.g. here). The key seems to be to edit .leaflet-popup-tip and .leaflet-popup-content-wrapper. But how can I do this in R (not using Shiny)?

相关:这个问题,但是该问题仅涉及修改弹出窗口中的元素,而不是弹出窗口本身。

Related: this question, which however only addresses modifying elements within a popup and not popups themselves.

我欢迎任何建议。

推荐答案

也许您可以使用打包 htmltools 来获取所需的内容。

Maybe you could use the package htmltools to get what you want.

map2 <- leaflet() %>%
    addPolygons(data = map , 
                group = map$NUTS_ID,
                fillColor = "grey",
                weight = 1,
                color = "black") %>%
    addPopups(lng = 16.3, lat = 47, popup = "Paint it black!")

library(htmltools)
browsable(
  tagList(list(
    tags$head(
      tags$style(
        ".leaflet-popup-content-wrapper {
    background: black;
    color: #ffffff;
    padding: 2px;
border-radius: 0px;
    }
        "
      )
    ),
    map2
  ))
)

这篇关于在R中修改传单弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆