首页 > 解决方案 > 我的闪亮应用程序在我调用它时删除了我的 Markdown 的内容并且不保存为 pdf

问题描述

我正在尝试创建一个闪亮的应用程序,该应用程序调用 Markdown 来下载带有包含金融股票的文本条目的 PDF

但是当我按下下载按钮时,降价内容被删除

此外,当我单击生成报告时,它会打开一个文件资源管理器并要求我保存一个名为报告的文件,但没有生成任何内容。在控制台中,我收到以下消息:

创建的输出:Reporte_consulta_tu_accion_andes.pdf

这是我的闪亮代码:

 library(shiny) 
  library(quantmod)
  library(xts)
  library(formattable)
  library(TTR)
  library(stringi)
  library(docxtractr)
  library(shinyWidgets)
  library(shinythemes)
  library(tidyverse)
  library(tidyquant)
  library(plotly)
  library(ggplot2)
  library(knitr)
  shinyApp(
      ui = fluidPage(
          textInput("text","generar"),
          downloadButton("report", "Generate report"),
          textOutput("a")
          
          
      ),
      server = function(input, output) {
          
        #setwd("C:/Users/SAMUELYAICEL/Desktop/Escritorio/Blog_data_info/blog_data_info")
          output$report <- downloadHandler(
              # For PDF output, change this to "report.pdf"
              filename = "Reporte_consulta_tu_accion_andes.pdf",
              content = function(file) {
                  # Copy the report file to a temporary directory before processing it, in
                  # case we don't have write permissions to the current working dir (which
                  # can happen when deployed).
                  wd <- getwd()
                  tempReport <- file.path(wd, "Reporte_consulta_tu_accion_andes.rmd")
                
                  file.copy("Reporte_consulta_tu_accion_andes.pdf", 
                            tempReport, overwrite = TRUE)
                  
                  # Set up parameters to pass to Rmd document
                  params <- list(text = input$text)
                  output$a <- reactive(input$text)
                  # Knit the document, passing in the `params` list, and eval it in a
                  # child of the global environment (this isolates the code in the document
                  # from the code in this app).
                  rmarkdown::render(tempReport, 
                                    output_file = file,
                                    output_format = pdf(),
                                    params = params,
                                    envir = new.env(parent = globalenv())
                  )
              }
          )
      }
  )
  
  shinyApp(ui = ui, server = server)

还有我的 Rmd 文件:

---
output: pdf_document
fontsize: 11pt
geometry: margin=2cm
number_sections: true
header-includes:
  - \usepackage{fancyhdr}
  - \usepackage{lipsum}
  - \pagestyle{fancy}
  - \fancyhead[RO,LE]{Andes }
  - \fancyfoot[RO,LE]{@Andes}
params:
  text: NA
---

```{r, include=FALSE}
options(tinytex.verbose = TRUE)
```

```{r}
params[["text"]]
```

```{r setup, include=FALSE}
library(quantmod)
library(xts)
library(formattable)
library(TTR)
library(stringi)
library(docxtractr)
library(shinyWidgets)
library(shinythemes)
library(tidyverse)
library(tidyquant)
library(plotly)
library(ggplot2)
library(knitr)
ticker <- params[["text"]]
prices3 <- getSymbols(params[["text"]])
prices3
what_metrics <- yahooQF(c("Name",
                          "Symbol",
                          "Market Capitalization",
                          "P/E ratio",
                          "Dividend Yield",
                          #"Percent Change From 20-day Moving Average",
                          "Percent Change From 50-day Moving Average",
                          "Percent Change From 200-day Moving Average"))
Compania  <- getQuote(prices3, what=what_metrics)
```

我是初学者,谁能告诉我我做错了什么?

标签: rshinydownloadmarkdownshinyapps

解决方案


推荐阅读