Abe
August 25, 2020, 10:29am
1
Hello, Dear R Community I need your help regarding shiny. I am getting error downloading report when app is deployed on shiny and rsconnect. But locally it is working fine. I have attched the log
library(shiny)
library(sdcMicro)
ui <- fluidPage(
titlePanel("Sample SDC Report"),
uiOutput("ui_export_report")
)
server <- function(input, output) {
data(testdata)
sdcObj <- createSdcObj(
testdata,
keyVars = c('urbrur', 'roof', 'walls', 'water', 'electcon', 'relat', 'sex'),
numVars = c('expend', 'income', 'savings'), w = 'sampling_weight'
)
output$ui_export_report <- renderUI({
fluidRow(column(12,
shiny::downloadButton("myRepDownload", "Save report", btn.style = "primary"), align = "center"
))
})
output$myRepDownload <- shiny::downloadHandler(
filename = function() {
paste0("sdcreport-", Sys.Date(), ".html")
},
content = function(file) {
sdcMicro::report(
sdcObj,
outdir = tempdir(),
filename = "tmp",
title = "SDC-Report",
internal = TRUE,
verbose = FALSE
)
f_tmp <- file.path(tempdir(), "tmp.html")
on.exit(file.remove(f_tmp))
file.copy(from = f_tmp, to = file)
}
)
}
shinyApp(ui = ui, server = server)
my assumption would be that sdcMicro::report wants to use interim files, and the default working directory isnt appropriate for that, so maybe using someithng like withr package, with_tempdir() would help.
Abe
August 25, 2020, 12:55pm
3
nirgrahamuk:
with_tempdir()
Thank you @nirgrahamuk , Do you mean changing tempdir() to with_tempdir(), if so I did it and it did not work as well
no. tempdir() is for your output and you would still want that, but you want the working directory to be different (perhaps) so with_tempdir() should wrap your function
with_dir(tempdir(), sdcMicro::report(
sdcObj,
outdir = tempdir(),
filename = "tmp",
title = "SDC-Report",
internal = TRUE,
verbose = FALSE
))
Abe
August 25, 2020, 1:01pm
5
Oh, I see your point let me try that, Thank you for your support. I will update you shortly
Abe
August 25, 2020, 1:13pm
6
Unfortunately, It did not solve the problem same issue
Abe
August 25, 2020, 1:17pm
7
I changed server part to this
output$myRepDownload <- shiny::downloadHandler(
filename = function() {
paste0("sdcreport-", Sys.Date(), ".html")
},
content = function(file) {
with_dir(tempdir(), sdcMicro::report(
sdcObj,
outdir = tempdir(),
filename = "tmp",
title = "SDC-Report",
internal = TRUE,
verbose = FALSE
))
f_tmp <- file.path(tempdir(), "tmp.html")
on.exit(file.remove(f_tmp))
file.copy(from = f_tmp, to = file)
}
)
}
shinyApp(ui = ui, server = server)
Abe:
sdcMicro::report
I suppose the next thing to do is to try and set Knitr options for your project...
and/or raise an issue with the sdcMicro package authors.
https://github.com/sdcTools/sdcMicro/search?q=knitr&type=Issues
Abe
August 25, 2020, 1:27pm
9
Thank you @nirgrahamuk , I will explore it
system
Closed
October 18, 2020, 5:27pm
10
This topic was automatically closed 54 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.