r - 我的闪亮应用程序在我调用它时删除了我的 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)
```
我是初学者,谁能告诉我我做错了什么?
解决方案
推荐阅读
- javascript - 需要时如何将整个对象转换为数组?
- java - Maven - 尽管存在,但在中央存储库中找不到杰克逊工件?
- python - 如何使用plotly(Python)将鼠标悬停在具有相同x轴的多个图表上?
- python - 在 matplotlib.pcolor() 中使用 x、y 数组作为像素位置和 z 作为颜色值时的参数数量错误
- python - 如果字段值在外部列表中,Django 注释布尔值
- azure - 如何使用 Azure App 代表用户发送电子邮件?
- javascript - 单击第一个链接会触发对其余链接的单击
- tensorflow - 优化二元焦点损失和骰子损失
- kubernetes - Helm Charts 在不同的命名空间中创建秘密
- react-native - React Native 中的嵌套堆栈导航器和抽屉导航器