rmarkdown文档中的中心传单 [英] Center leaflet in a rmarkdown document

查看:80
本文介绍了rmarkdown文档中的中心传单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个HTML文档,并在其中放置一个居中的传单小部件.

I want to create an html document with a centered leaflet widget inside it.

---
title: "Exemple"
author: "Antoine Bichat"
date: "31/08/2018"
output: html_document
---

```{r leaflet, fig.align="center"}
library(leaflet)

leaflet() %>%
  addTiles() %>% 
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
```

使用fig.align="center"的第一个想法无效.

The first idea with fig.align="center" doesn't work.

我发现了这个问题,我将其调整为适合我的情况:

I found this question and I adapted it to my case:

<style>
/* resize the widget container */
.leaflet { 
  width: 80% !important;
}

/* center the widget */
div.leaflet-control-container {
  margin: auto !important;
}
</style>

但是如果我不想将out.width设置为100%(并且我也不想这样做),那将是行不通的.

but if I don't want to have an out.width of 100% (and I don't want to), it doesn't work.

或者也许我做错了... 实际上,我更喜欢100%R/Rmarkdown解决方案,但我对所有内容都持开放态度:)

Or maybe I did it wrong... Actually I prefer a 100% R/Rmarkdown solution but I'm open to everything :)

推荐答案

尝试.html-widget

---
title: "Exemple"
author: "Antoine Bichat"
date: "31/08/2018"
output: html_document
---

<style>
.html-widget {
    margin: auto;
}
</style>

```{r leaflet, fig.align="center"}
library(leaflet)

leaflet() %>%
  addTiles() %>% 
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
```

这将使每个htmlwidget居中. 您还可以输入:

That will center every htmlwidget. You can also put :

<style>
.leaflet {
    margin: auto;
}
</style>

仅使传单居中.

这篇关于rmarkdown文档中的中心传单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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