我有以下交互式Rmarkdown文件,我想将其传递给Shiny,因为我想将它作为word文档下载,并显示它的预览。正如你在Rmarkdown中看到的,我有一个情节图,用户可以在其中与它交互。
R标记
---
title: "test_plotly"
output: html_document
date: "2024-05-28"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
library(plotly)
plotly::plot_ly(data=cars, type='scatter',mode='lines')%>%
add_trace(x=~speed,y=~dist)
这是一个闪亮的应用程序输出,但不显示绘图,我不想要静态绘图,我想要显示交互式绘图。我该怎么做?
library(shiny)
library(knitr)
ui <- shinyUI(
fluidPage(
uiOutput('markdown')
)
)
server <- function(input, output) {
output$markdown <- renderUI({
HTML(markdown::markdownToHTML(knit('test_plotly.Rmd', quiet = TRUE), fragment.only=TRUE))
})
}
shinyApp(ui, server)