You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Quarto中插入格式化非可执行代码及集成任意代码的正确方法

在Quarto中集成代码的正确方式及相关疑问解答

1. 集成任意代码(以Overpass QL为例)

Quarto里集成代码分两种场景,对应不同处理方式:

  • 需要执行的代码:如果要让Overpass QL实际运行并获取数据,得用能发起HTTP请求的编程语言(比如Python、R)封装查询逻辑。以Python为例:
import requests

# 定义Overpass API地址和查询语句
overpass_url = "https://overpass-api.de/api/interpreter"
overpass_query = """
[out:json];
area["name"="北京"]->.searchArea;
node["amenity"="cafe"](area.searchArea);
out body;
>;
out skel qt;
"""
# 发送请求并解析结果
response = requests.get(overpass_url, params={'data': overpass_query})
osm_data = response.json()
  • 仅用于展示的代码:如果只是想展示Overpass QL代码,不需要执行,直接用指定语言的普通代码块即可:
[out:json];
area["name"="北京"]->.searchArea;
node["amenity"="cafe"](area.searchArea);
out body;
>;
out skel qt;

2. 代码单元格能否作为非可执行代码块?

Quarto的代码单元格(带语言标识的可执行块,比如{r}、{python})默认用来运行代码,但也可以改成非可执行:

  • 在代码块参数里添加eval: false,这样代码只会展示,不会执行,示例:
[out:json];
area["name"="北京"]->.searchArea;
node["amenity"="cafe"](area.searchArea);
out body;
>;
out skel qt;
  • 另外,如果你不需要执行代码,也可以直接用不带执行标记的普通代码块(也就是只写```overpassql),这种本身就是纯展示的非可执行块,和代码单元格的区别是没有执行相关的配置选项。

内容的提问来源于stack exchange,提问作者winnewoerp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 13:02:17