The below code auto downloads the report file after passing the variables but I want to save the file to a specific path and view the same in UI also.
library(shiny)
library(httr2)
ui <- fluidPage(
dateInput("startDate", "Start Date"),
dateInput("endDate", "End Date"),
textInput("rn", "Report Number"),
actionButton("runReport", "Run Report"),
uiOutput("reportOutput")
)
server <- function(input, output, session) {
observeEvent(input$runReport, {
startDate <- input$startDate
endDate <- input$endDate
reportNumber <- input$rn
# Generate the report URL with the variables
reportURL <- paste0("http://localhost/ReportServer?%2fReport1",
"&StartDate=", format(startDate, "%Y-%m-%d"),
"&EndDate=", format(endDate, "%Y-%m-%d"),
"&rn=", reportNumber,
"&rs:Command=Render&rs:Format=PDF&rc:LinkTarget=_self"
)
output$reportOutput <- renderUI({
# Render the iframe with the dynamically generated source filename
tags$iframe(style = "width: 100%; height: 500px", src = reportURL)
})
response <- httr2::request(reportURL)
# Perform the request
result <- httr2::req_perform(response)
})
}
shinyApp(ui, server)
I tried updating the code with download.file function like shown below but didn't worked out
# Generate the report URL with the variables
reportURL <- paste0("http://desktop-lgjc8bc/ReportServer?%2fReport1",
"&StartDate=", format(startDate, "%Y-%m-%d"),
"&EndDate=", format(endDate, "%Y-%m-%d"),
"&rn=", reportNumber,
"&rs:Command=Render&rs:Format=PDF&rc:LinkTarget=_self"
)
saveDir <- "D:/Projects/Report1.pdf" # Replace with the desired directory path
# Save the report to the specified directory
download.file(reportURL, saveDir, mode = "wb")
i tried with httr and httr2 library packages also. All throwing same error HTTP status was '401 Unauthorized
please share your thoughts and workarounds for this. Thanks in advance