目标 我想在现有的R Shiny应用程序中呈现多个Quarto文件(.qmd)
当前解决方案 我的当前解决方案是将Quarto文件呈现为html,并在R Shiny应用程序中显示html文件,但这对于交互式图表不起作用。我知道我可以在Quarto文档中使用shiny,但我想在R Shiny中呈现带有其功能的quarto。
可重复示例代码
app.R
library(shiny)
library(quarto)
ui <- fluidPage(titlePanel("Reproducable Example"),
sidebarLayout(
sidebarPanel(
textInput(inputId = "user_argument", label = "Argument"),
br(),
actionButton("render_button", "Render Quarto ")
),
mainPanel(uiOutput("quarto_output"))
))
server <- function(input, output) {
observeEvent(input$render_button, {
quarto::quarto_render("example.qmd",
execute_params = list(user_arg = input$user_argument))
html <- readLines("qmd_output.html")
# Display html in output
output$quarto_output <- renderUI({
tags$iframe(srcdoc = html,
height = "500px",
width = "100%")
})
})
}
# Run the application
shinyApp(ui = ui, server = server)
example.qmd
---
title: "Quarto HTML Basics"
format:
html:
code-tools: true
self-contained: true
output-file: "qmd_output.html"
theme: cosmo
execute:
warning: false
params:
user_arg: NA
---
```{r}
#| label: fig-temperatures
#| fig-cap: "New Haven Temperatures"
library(dygraphs)
dygraph(nhtemp) %>%
dyRangeSelector(dateWindow = c("1920-01-01", "1960-01-01"))
```
## Argument
My name is `r params$user_arg`.
观察
- 当quarto渲染html时,交互式图表可以正常工作,但在R Shiny中呈现相同的html时无法正常工作。
- 我使用iframe是因为直接将html插入到R Shiny中也会覆盖插入的html的css。
帮助
- 是否有其他方法在R Shiny应用程序中呈现Quarto文件?
- 如果没有,是否有任何选项可以从html中呈现Shiny的交互式图表?