I have the following interactive Rmarkdown file and I want to pass it to Shiny as I want to download it as both a word document and I want to display a preview of it. As you can see in the Rmarkdown file, I have a plotly plot where the user can interact with it.
Rmarkdown
---
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)
This is the shiny app output but the plotly plot doesn’t display and I don’t want a static plotly plot, I want the interactive one displayed. How do I do that?
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)