I am trying to create a shiny app in which I can upload an excel file with a fixed structure (all excel files to be uploaded have the same structure). Then the idea is to open this excel file in a .Rmd where it will be manipulated. The code below is a simplified version of the .R and the .Rmd. It works on my computer but the deployment fails. I have been surprisingly unsuccessful after reproducing the solutions for similar questions but dealing with the upload of a .csv instead of an excel. I tried several options, most of them work on my computer, none of them were deployed. In some cases, the problem is "datain should be reactive" (or something similar) and "path does not exist". I would really appreciate it if you can try to deploy the app before posting a solution. Beforehand thank you very much for your feedback.
app
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("datain", "Upload WHIP Export", buttonLabel = "Choose file..."),
downloadButton("report", "Generate report")
),
mainPanel("Have fun")
)
)
server <- function(input, output) {
output$report <- downloadHandler(
filename = "report.html",
content = function(file) {
report<-"test.Rmd"
src <- normalizePath(report)
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(src, report, overwrite = TRUE)
params <- list(datain = input$datain$datapath)
rmarkdown::render(report,
# output_file = output,
params = params,
envir = new.env(parent = globalenv())
)
}
)
}
shinyApp(ui, server)
test.Rmd
---
title: "Test"
output: html_document
params:
datain: NA
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(readxl)
number_of_columns=619 # counted the number of columns in the original excel
spec<-read_excel(path = params$datain, sheet = 1, col_types = rep("text", number_of_columns))
spec$Country