我想在PDF上打印Shiny小部件,而不在Rmarkdown文件上重新定义它们(所有小部件已在server.R文件中定义)。
但是,当我在Rmarkdown文件上使用“ output $ widget_name”调用小部件时,收到消息Error in shinyoutput: Reading objects from shinyoutput object not allowed.
。
请在下面找到可复制的示例
这是app.R
library(shiny)
library(plotly)
library(leaflet)
library(rmarkdown)
shinyApp(
ui = fluidPage(
plotlyOutput("distPlot"),
actionButton("report", "Generate report")
),
server = function(input, output) {
output$distPlot <- renderPlotly({
data <- data.frame(c(1:100), rnorm(100, mean = 0))
plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines')
})
observeEvent(input$report,{
render(input="report.Rmd", output_file= "my_report.pdf")
system(' open "my_report.pdf"')
})
}
)
这是report.Rmd
---
title: "Print shiny widgets "
always_allow_html: yes
output:
pdf_document: default
---
```{r}
library(shiny)
library(rmarkdown)
library(plotly)
library(leaflet)
output$distPlot
```
有可能实现吗? 预先感谢