使用 Hugo-future-imperfect 主题的 DT 包不适用于 blogdown [英] DT package not working with blogdown using hugo-future-imperfect theme
问题描述
我有一个基于 Hugo-future-imperfect 主题的 blogdown 站点,其中在 rmd 中正确创建了 DT 输出,但在应用 serve_site/build_site 时未显示数据(尽管有标题)
I have a blogdown site based on the hugo-future-imperfect theme where a DT output is created correctly in the rmd but the data is not shown (although the headings are) when applying serve_site/build_site
我创建了两个全新的网站(因此没有其他复杂情况)来说明这个问题.这是代码和输出
I have created two brand new sites ( so with no other complications) to illustrate the issue. This is the code and outputs
```{r DT}
library(DT)
library(tidyverse)
iris %>%
datatable()
```
a) 默认主题
b) 雨果不完美
推荐答案
来自 https://owi.usgs.gov/blog/leaflet/ 和 https://github.com/rstudio/blogdown/issues/20 答案是在 iframe 中显示输出.所以:
From https://owi.usgs.gov/blog/leaflet/ and https://github.com/rstudio/blogdown/issues/20 the answer is to display the output in an iframe. So:
将输出绑定到代码中的变量,不显示此块的输出:
Bind the output to a variable in your code, do not display the output from this block:
```{r, message=FALSE, warning=FALSE, include=FALSE}
library(DT)
library(tidyverse)
d1 <- iris %>%
datatable()
d1
```
在下一个块中,将小部件保存到一个单独的文件中(隐藏此文件的代码和输出).
In the next block, save the widget to a separate file (hide the code and output from this one).
```{r, message=FALSE, warning=FALSE, include=FALSE}
library(htmlwidgets)
library(htmltools)
htmlwidgets::saveWidget(d1, file = "d1.html", selfcontained = TRUE)
```
小部件没有保存为 d1.html,而是创建了一个文件夹 d1,并在该文件夹中创建了一个文件 index.html.您需要从 iframe 标记(在代码块之外)引用此索引文件
The widget is not saved as d1.html, instead a folder d1 is created and a file index.html is created in the folder. You need to reference this index file from an iframe tag (outside of a code block)
<iframe seamless src="../d1/index.html" width="100%" height="500"></iframe>
您应该会在页面中看到此 iframe 的输出.
You should see the output from this iframe in your page.
这不是一个很好的解决方法.希望这个问题很快会在 rblogdown 中得到解决.
It's not a pretty workaround. Hopefully the problem will be solved within rblogdown soon.
这篇关于使用 Hugo-future-imperfect 主题的 DT 包不适用于 blogdown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!