我试图在Rmarkdown中转换我的Rshiny的一部分,但是当我尝试运行这个例子时,我得到了一个错误,我该如何处理它?这段代码是Rshiny应用程序示例的一部分,但是当我试图运行一些错误的东西时,或者你能帮我找到一些脚本来将Rshiny中的一些表格和图形打印到Rmarkdown中吗?
Aserver <-function(input, output) {
regFormula <- reactive({
as.formula(paste('mpg ~', input$x))
})
output$regPlot <- renderPlot({
par(mar = c(4, 4, .1, .1))
plot(regFormula(), data = mtcars, pch = 19)
})
output$downloadReport <- downloadHandler(
filename = function() {
paste('my-report', sep = '.', switch(
input$format, PDF = 'pdf', HTML = 'html', Word = 'docx'
))
},
content = function(file) {
src <- normalizePath('report.Rmd')
# temporarily switch to the temp dir, in case you do not have write
# permission to the current working directory
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(src, 'report.Rmd', overwrite = TRUE)
library(rmarkdown)
out <- render('report.Rmd', switch(
input$format,
PDF = pdf_document(), HTML = html_document(), Word = word_document()
))
file.rename(out, file)
}
)
}
Aui <- fluidPage(
title = 'Download a PDF report',
sidebarLayout(
sidebarPanel(
helpText(),
selectInput('x', 'Build a regression model of mpg against:',
choices = names(mtcars)[-1]),
radioButtons('format', 'Document format', c('PDF', 'HTML', 'Word'),
inline = TRUE),
downloadButton('downloadReport')
),
mainPanel(
plotOutput('regPlot')
)
)
)
shinyApp(Aui, Aserver)这就是错误
Warning: Error in abs_path: The file 'report.Rmd' does not exist.
[No stack trace available]谢谢
发布于 2020-09-04 03:48:54
你应该区分两条路径:
编织结果的路径
您可以使用getwd()获取应用程序运行的路径。
如果没有显式指定路径,则report.Rmd应该与应用程序位于相同的目录中,以便应用程序可以使用它。
确保Report.Rmd在getwd()目录下,或者指定Report.Rmd的路径:
render(file.path('/custom/directory','report.Rmd'), ...https://stackoverflow.com/questions/63713715
复制相似问题