【发布时间】:2020-05-14 11:51:23
【问题描述】:
假设我们有我在 RStudio 上构建的“运行时:闪亮”RMD 文件。它有 4 个主要部分:
---
title: "Theory"
output: html_document
runtime: shiny
---
Part 1: html code
<style type="text/css">
h1.title {
text-align: center;
color: DarkBlue;
font-size: 38px;
}
p{
font-size: 18pt;
font-family: times, serif;
}
</style>
<br>
</br>
---
Part2: Inline equations
<p>
This is an inline equation: $y = \frac{a}{b}$
</p>
<br>
</br>
---
Part3: Standalone equations
$$y = \frac{a}{b} $$
<br>
</br>
---
Part4: Embedded shiny inputs and outputs
```{r eruptions, echo=FALSE}
inputPanel(
selectInput("n_breaks", label = "Number of bins:",
choices = c(10, 20, 35, 50), selected = 20),
sliderInput("bw_adjust", label = "Bandwidth adjustment:",
min = 0.2, max = 2, value = 1, step = 0.2)
)
renderPlot({
hist(faithful$eruptions, probability = TRUE, breaks = as.numeric(input$n_breaks),
xlab = "Duration (minutes)", main = "Geyser eruption duration")
dens <- density(faithful$eruptions, adjust = input$bw_adjust)
lines(dens, col = "blue")
})
我可以在 rStudio 中“运行文档”,它运行良好。
现在我保存那个 .rmd 文件,然后在构建我的闪亮应用程序时引用它:
library(shiny)
ui <- shinyUI(
fluidPage(
shinyWidgets::panel(
fluidRow(
column(12, align="center",
actionButton("rmd", "Test")
)
))
# ,includeHTML(rmarkdown::render("test_rmd.Rmd"))
)
)
server <- function(input, output) {
observeEvent(input$rmd, {
output$markdown <- renderUI({
includeHTML(rmarkdown::render("test_rmd.Rmd"))
})
})
}
shinyApp(ui, server)
当我运行该应用程序时,它无法成功显示除文本本身之外的“运行时:闪亮”rmd 文件的所有 4 个部分。 我问的原因是因为我最终想要构建一个操作按钮,单击该按钮时将显示“运行时:闪亮”rmd 文件。
是否无法渲染“runtime: shiny”rmd 文件,因为它们与闪亮的应用程序格式不兼容?
附:我可以通过将 rmd 转换为 html IF 第 4 部分(“嵌入式闪亮输入和输出”)被删除(否则我得到一个错误)来解决这个问题。但如果可能的话,我想保留它。会让我的生活更轻松。
【问题讨论】:
标签: r shiny r-markdown