R:标记表单元格内的代码输出
我正在尝试将R lot输出嵌入html表的单元格中。就我所知: app.RR:标记表单元格内的代码输出,r,shiny,r-markdown,knitr,R,Shiny,R Markdown,Knitr,我正在尝试将R lot输出嵌入html表的单元格中。就我所知: app.R require(shiny) require(knitr) require(ggplot2) d = iris ui = fluidPage( uiOutput('markdown') ) server = function(input, output, session) { output$markdown <- renderUI({ HTML(knit(text = paste(readLi
require(shiny)
require(knitr)
require(ggplot2)
d = iris
ui = fluidPage(
uiOutput('markdown')
)
server = function(input, output, session) {
output$markdown <- renderUI({
HTML(knit(text = paste(readLines('table.html'), collapse='\n')))
})
}
shinyApp(ui, server)
知道如何删除反勾号和散列符号吗?工作工具链如下所示: 表2.Rmd 或公平地
table.Rmd -> table.html via knit2pandoc -> shiny via includeHTML
renderMarkdown
不喜欢表中的块
太棒了,非常感谢@thothal。显然在这方面做了一些努力。唯一的想法是:我注意到这会在
www/figure/unnamed-chunk-2-1.png
上生成一个文件。我想知道多个用户同时使用同一个文件的风险(例如,当他们的d
对象是不同的数据时)。有什么想法吗?我不是一个在不同用户之间如何共享空间的专家。不过,您可以将pandoc
配置为创建独立的html文件。在这种情况下,图片是base64
编码的,不通过链接包括在内。假设shinny
没有考虑到这一点,您还可以为区块生成的图形指定随机名称。将包括一个例子。
``` ## setosa ```
<!--pandoc
t: html
o: table.html
-->
```{r, echo = FALSE, include = FALSE}
opts_knit$set(base.dir = "www")
```
<table class='table'>
<tr>
<th>text field</th>
<th>sparkline</th>
</tr>
<tr>
<td>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.
</td>
<td>
```{r, echo = FALSE, include = TRUE}
qplot(Sepal.Length, Sepal.Width, data = d[d$Species == "setosa", ], geom = "line")
```
</td>
</tr>
</table>
library(shiny)
library(knitr)
library(ggplot2)
d <- iris
ui <- fluidPage(
uiOutput("markdown")
)
server <- function(input, output, session) {
output$markdown <- renderUI({
tmp <- knit("table.Rmd", quiet = TRUE) ## could combine these...
pandoc(tmp) ## ...two lines also in `knit2pandoc`
includeHTML("table.html")
})
}
shinyApp(ui, server)
table.Rmd -> table.md via knit -> table.html via pandoc -> shiny via inclueHTML
table.Rmd -> table.html via knit2pandoc -> shiny via includeHTML
does_translate <- "```{r}\nggplot2::qplot(1, 2)\n```"
does_not_translate <- "<table><tr><td>\n```{r}\nggplot2::qplot(1, 2)\n```\n</td></tr></table>"
cat(knit2html(text = does_translate, fragment.only = TRUE))
# vs.
cat(knit2html(text = does_not_translate, fragment.only = TRUE))
```{r, echo = FALSE, include = FALSE}
opts_knit$set(base.dir = "www")
knitr::opts_chunk$set(
fig.process = function(filename) {
wd <- dirname(filename)
ext <- file_ext(filename)
new_filename <- tempfile(tmpdir = wd, fileext = paste0(".", ext))
file.copy(filename, new_filename)
unlink(filename)
ifelse(file.exists(new_filename), new_filename, filename)
}
)
```