我创建了一篇四开版博客文章,其中包含许多leaflet在 R 中生成的地图。由于每个地图的数据都嵌入在 html 文件中,因此文件本身非常大。这会导致托管该文件的服务器出现问题。
我想让html文件变小。embed-resources: false Quarto 中的YAML 选项意味着库(例如leaflet.js)存储在单独的文件中。有帮助,但数据仍然存储在 html 中(每个地图一次)。我正在尝试从单独的文件加载数据本身。这是一个最小的文件示例qmd:
---
format:
html:
embed-resources: false
---
```{r}
leaflet::leaflet(elementId = "map1") |>
leaflet::addTiles() |>
leaflet::addMarkers(lng = 174.768, lat = -36.852, popup = "The birthplace of R")
```
Run Code Online (Sandbox Code Playgroud)
当我quarto render这样做时,它会创建一个 html 文件,该文件在浏览器中打开时显示地图。该文件包含以下地图数据<div>:
<div class="leaflet html-widget html-fill-item-overflow-hidden html-fill-item" id="map1" style="width:100%;height:464px;"></div>
<script type="application/json" data-for="map1">{**json**}</script>
</div>
Run Code Online (Sandbox Code Playgroud)
我写的地方{**json**}有一长串 json,其中包含地图坐标、CRS 和各种选项。
在我看来,我也许可以将 json 内容复制到文件中,然后更改标签<script>以从该文件加载数据:
---
format:
html: …Run Code Online (Sandbox Code Playgroud) 我正在使用四开本创建一份长 PDF 报告。我想包括两种格式的交叉引用:
正如3.1 节中讨论的
正如我的精彩部分中所讨论的。
可以这样实现:
---
format:
pdf:
number-sections: true
---
# Why Stack Overflow is so great {#sec-stack}
I can use style 1, the section number, with the explicit ID, e.g. as seen in @sec-stack.
I can use style 2, the section title, with a link [Why Stack Overflow is so great].
I can also custom text with [Custom text before the link][Why Stack Overflow is so great].
Run Code Online (Sandbox Code Playgroud)
这会产生所需的输出:
问题是该文件正在由几位作者重新起草。如果章节标题从Why Stack …
rextendr我正在尝试使用R 包和 Rust箱来学习如何连接 Rust 和 R(除了学习 Rust 本身)extendr。当我在 R 函数的输入中Expected a vector type.使用时遇到错误。:
下面是一个简单函数的示例,TRUE如果输入向量中的所有值都为正,则返回,FALSE否则返回。当我在输入中使用时它似乎工作正常c(),但当我使用:.
library(rextendr)\n\n# create a Rust function that checks if all values in the input are\n# greater than 0\nrust_function(\n "fn all_positive(input: &[f64]) -> bool {\n let mut out = true;\n for i in input.iter() {\n if *i <= 0.0 {\n out = false;\n break\n } \n }\n out\n }"\n)\n#> \xe2\x84\xb9 build directory: …Run Code Online (Sandbox Code Playgroud) 我对 python-docx 比较陌生。我试图更改现有文档中表格的行距,但它更改了文档中所有表格的行距。
这是一个最小的、可重现的示例,从头开始创建一个包含三个表的文档:
from docx import Document
from docx.shared import Inches
from docx.shared import Pt
from docx.enum.text import WD_LINE_SPACING
document = Document()
# Some sample text to add to tables
records = (
(3, '101', 'Spam'),
(7, '422', 'Eggs'),
(4, '631', 'Spam, spam, eggs, and spam')
)
# Create table 0
table = document.add_table(rows=1, cols=3)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Qty'
hdr_cells[1].text = 'Id'
hdr_cells[2].text = 'Desc'
for qty, id, desc in records:
row_cells = table.add_row().cells
row_cells[0].text = str(qty) …Run Code Online (Sandbox Code Playgroud) 我正在尝试将上次访问的字段添加到四开 PDF 中的 Web 引用。这是一个最小的文件示例qmd:
---
title: "How to cite a URL with access date"
format: pdf
bibliography: references.bib
---
I am using @stackoverflow1, @stackoverflow2 and @stackoverflow3.
# References
::: {#refs}
:::
Run Code Online (Sandbox Code Playgroud)
这是references.bib:
@online{stackoverflow1,
title = {Stack Overflow with note},
url = {https://stackoverflow.com/},
year = {2022},
note = {https://stackoverflow.com/, last accessed on 2022-12-30}
}
@online{stackoverflow2,
title = {Stack Overflow with urldate},
url = {https://stackoverflow.com/},
year = 2022,
urldate = {2022-12-30}
}
@online{stackoverflow3,
title = …Run Code Online (Sandbox Code Playgroud) 使用以下命令可以读取 json 文件:
library(jsonlite)
json_text <- readLines("tect.json", warn = FALSE, encoding = "UTF-8")
Run Code Online (Sandbox Code Playgroud)
json_data <- fromJSON(txt = paste(json_text, collapse = ""))
Run Code Online (Sandbox Code Playgroud)
tect.json 文件中的数据格式如下:
[
{
"id": 1,
"name": "Apple",
"color": "red",
"price": 0.99
},
{
"id": 2,
"name": "Banana",
"color": "yellow",
"price": 0.5
},
{
"id": 3,
"name": "Orange",
"color": "orange",
"price": 0.75
}
]
Run Code Online (Sandbox Code Playgroud)
但是,如果 tech.json 具有这种格式,如何将其作为 json 文件读取并将其转换为数据帧?
{"id": 1, "name": "Apple", "color": "red", "price": 0.99 }
{"id": 2, "name": "Banana", "color": "yellow", "price": 0.5 …Run Code Online (Sandbox Code Playgroud) I\xc2\xb4d 喜欢在栅格内插入缺失值:
\nr <- rast(xmin=0, xmax=10, ymin=0, ymax=10, nrows=50, ncols=50)\ne = rast(xmin=2, xmax=4, ymin=2, ymax=4, nrows=10, ncols=10)\nvalues(r) <- 1:ncell(r)\nvalues(e) <- 1:ncell(e)\n\nr=raster(r)\ne=raster(e)\nr[intersect(r,e)]=NA\nplot(r)\nRun Code Online (Sandbox Code Playgroud)\n我怎样才能做到这一点?
\n
我知道如何使用不同的方法(样条线、克里金法、IDW...)在点之间进行插值,但我不知道如何在多边形尺度上执行此操作。
\n