I have a "example.Rmd" file where I am creating a plotly plot. I want to call that plot into my shiny and show the plot in the shiny interface.
My "example.Rms" is like below :
---
title: "example"
output: html_document
params:
var1: default
var2: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```{r pressure, echo=FALSE}
p <- plotly::plot_ly(data = cars, x = ~params$var1, y = ~params$var2)
p
And my app code is as follows :
library(shiny)
ui <- fluidPage(
fluidRow(
column(3,
selectInput("v1", "X variable", names(cars))),
column(3,
selectInput("v2", "Y variable", names(cars))),
column(2,
actionButton("g_plot", "Generate Plot"))
)
)
server <- function(input, output){
observeEvent(input$g_plot, {
rmarkdown::render(
input = "~/example.Rmd",
params = list(
var1 = input$v1,
var2 = input$v2
)
)
})
}
shinyApp(ui, server)
By this code I am able to generate the report. But How can I show plot "p" in the shiny app?