Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 如何将一个绘图(renderPlot)作为参数从Shining app传递到R Markdown?_Variables_Parameters_Shiny_R Markdown - Fatal编程技术网

Variables 如何将一个绘图(renderPlot)作为参数从Shining app传递到R Markdown?

Variables 如何将一个绘图(renderPlot)作为参数从Shining app传递到R Markdown?,variables,parameters,shiny,r-markdown,Variables,Parameters,Shiny,R Markdown,我正在尝试使用R Markdown下载报告表单闪亮应用程序,但我迷路了!我需要将一个绘图从Shining作为参数传递到R Markdown,然后将此绘图包含在我的报告中。 我找了很多,但什么也没找到。我如何在我的报告中描绘这一点 服务器.R lm_dif_filter <- reactive({ lm_dif_corn[(lm_dif_corn$farmer == input$farmer) & (lm_dif_corn$Treat_X == 'Farmer'),] }

我正在尝试使用R Markdown下载报告表单闪亮应用程序,但我迷路了!我需要将一个绘图从Shining作为参数传递到R Markdown,然后将此绘图包含在我的报告中。 我找了很多,但什么也没找到。我如何在我的报告中描绘这一点

服务器.R

lm_dif_filter <- reactive({
    lm_dif_corn[(lm_dif_corn$farmer == input$farmer) & (lm_dif_corn$Treat_X == 'Farmer'),]
  })

output$difPlot <- renderPlotly({
      dif <- ggplot(data=lm_dif_filter(), aes(x=Treat_Y, y=dif)) +
             geom_bar(stat="identity",color = 'black', position=position_dodge(), width = 0.7)+
             geom_hline(yintercept = 0) + 
             #annotate("text", min(Treat_Y), 0, vjust = -1, label = "Farmer")+
             theme(legend.position = "none") +
             labs(x = "Treats", y = "Diff")

      ggplotly(dif)

一个简单的选择是不传递绘图,而是传递参数,并引用Shining app和Rmd doc使用的共享绘图函数。比如说,

闪亮的应用程序, 注意
源(“util.R”)
报告历史(参数$n)


来源(“util.R”)
图书馆(闪亮)
shinyApp(
ui=fluidPage(
sliderInput(“滑块”,“滑块”,1100,50),
下载按钮(“报告”、“生成报告”),
绘图输出(“报告历史”)
),
服务器=功能(输入、输出){

输出$report\u hist非常感谢,这真的很有帮助如果有人回答了问题,并且该答案解决了您的问题,那么您应该通过单击向上三角形进行向上投票,并通过单击答案旁边的灰色复选标记接受答案。这是在堆栈溢出中表示感谢的方式。由于您是本网站的新手,您应该了解当我问这个问题的时候,我的名声还不到15,所以我以前不能投票和得分作为回答。但现在我已经做到了。谢谢你提醒我。
output$report <- downloadHandler(
     filename = "report.pdf",
     content = function(file) {
       tempReport <- file.path(tempdir(), "report.Rmd")
       file.copy("report.Rmd", tempReport, overwrite = TRUE)

       # Set up parameters to pass to Rmd document
       params <- list(set_subtitle = input$farmer, plot =  output$difPlot)
       rmarkdown::render(tempReport, output_file = file,
                         params = params,
                         envir = new.env(parent = globalenv())
       )
     }
   )
---
title: "Some title"
params:
 set_subtitle: test
 plot: NA
subtitle: "`r params$set_subtitle`"
date: '`r format(Sys.Date(), "%B %d, %Y")`'

output:
  pdf_document:
    toc: yes 
header-includes:
    - \usepackage{fancyhdr}
always_allow_html: yes
---
\addtolength{\headheight}{1.0cm} 
\pagestyle{fancyplain} 
\lhead{\includegraphics[height=1.2cm]{bg.png}} 
\renewcommand{\headrulewidth}{0pt} 


```{r, include=FALSE}
options(tinytex.verbose = TRUE)
knitr::opts_chunk$set(echo = FALSE)
cat(params$plot)