無論如何要采用如下代碼,它產生一個簡單的圓圈,并在編織成 HTML 時產生結果影像?
<svg height="100" width="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="#757575" /></svg>
作為參考為什么我有代碼而不是影像,這個 SVG 是從 JSON blobs 中提取的文本。如果我將它保存到擴展名為 .svg 的文本檔案中,它可以正常打開。這段代碼的最終結果將是一個閃亮的應用程式,它顯示來自各種 JSON blob 的 SVG。
編輯:Stéphane Laurent 的解決方案(下)奏效了。我沒有解釋這個 SVG 會在一個資料框內,這給渲染帶來了另一個挑戰。但是,他們的回答使我想到了這一點:
```{r}
tribble(~id, ~svg,
1, '<svg height="100" width="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="#757575" /></svg>',
2, '<svg height="100" width="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="#757575" /></svg>') %>%
knitr::kable(escape = F) %>%
kableExtra::kable_styling()
uj5u.com熱心網友回復:
正如Limey提到的,您可以使用rsvg包轉換為png。但是你可以簡單地將svg標簽粘貼到 Rmarkdown 檔案中,質量比png好:
---
title: "Untitled"
author: "Stéphane Laurent"
date: '2022-05-20'
output: html_document
---
<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="#757575" /></svg>
注意: 代碼不要縮進,否則會呈現為代碼塊。

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/481559.html
上一篇:搜索圖示在移動設備上重復兩次
