Reputation: 8404
I have the shiny app below in which I create .rmd
report and then try to downlaod it. While Im in browser mode it is saved in the 'Downloads' folder instead of being saved in the folder that I have set with: output_dir = "C:/Users/User/Documents/Hodgkins/www",
the ex.rmd
---
title: "An example Knitr/R Markdown document"
output: pdf_document
---
{r chunk_name, include=FALSE}
x <- rnorm(100)
y <- 2*x + rnorm(100)
cor(x, y)
and the app
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
library(knitr)
mytitle <- paste0("Life, Death & Statins")
dbHeader <- dashboardHeaderPlus(
titleWidth = "0px",
tags$li(a(
div(style="display: inline;padding: 0px 0px 0px 0px;vertical-align:top; width: 150px;", actionButton("res", "Results"))
),
class = "dropdown")
)
shinyApp(
ui = dashboardPagePlus(
header = dbHeader,
sidebar = dashboardSidebar(width = "0px",
sidebarMenu(id = "sidebar", # id important for updateTabItems
menuItem("Results", tabName = "res", icon = icon("line-chart"))
) ),
body = dashboardBody(
useShinyjs(),
tags$script(HTML("$('body').addClass('fixed');")),
tags$head(tags$style(".skin-blue .main-header .logo { padding: 0px;}")),
tabItems(
tabItem("res",
tags$hr(),
tags$hr(),
fluidRow(
column(3,
div(style="display: block; padding: 5px 10px 15px 10px ;",
downloadButton("report",
HTML(" PDF"),
style = "fill",
color = "danger",
size = "lg",
block = TRUE,
no_outline = TRUE
) )
),
column(6,
uiOutput('markdown'))))
),
)
),
server<-shinyServer(function(input, output,session) {
hide(selector = "body > div > header > nav > a")
output$markdown <- renderUI({
HTML(markdown::markdownToHTML(knit('ex.rmd', quiet = TRUE)))
})
output$report <- downloadHandler(
filename = "report.pdf",
content = function(file) {
src <- normalizePath('ex.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, 'ex.Rmd', overwrite = TRUE)
library(rmarkdown)
out <- render(input = 'ex.Rmd',
output_format = pdf_document(),
output_dir = "C:/Users/User/Documents/Hodgkins/www",
params = list(data = data)
)
file.rename(out, file)
}
)
}
)
)
Upvotes: 0
Views: 106
Reputation: 21287
You need to define output_file
when you define output_dir
. Please try this
output$report <- downloadHandler(
filename = "report.pdf",
content = function(file) {
src <- normalizePath('ex.Rmd')
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(src, 'ex.Rmd', overwrite = TRUE)
library(rmarkdown)
out <- render(input = 'ex.Rmd',
output_format = pdf_document(),
output_file = "reportt.pdf",
#output_dir = "C://My Disk Space//temp//",
output_dir = "C://Users//User//Documents//Hodgkins//www//",
params = list(data = data)
)
#file.rename(out, file)
file.copy(out, file)
}
Upvotes: 1