I created the following program in Shiny with which I pretend that by clicking on the "Generate Excel" button I can download the excel.
But in doing so I get an error in which it tells me that it can not find the file.
Does anyone know what can be wrong?
library(shinyjs)
shinyUI(fluidPage(
useShinyjs(),
titlePanel("Informe de categoría 360. Ecuación de ventas"),
sidebarLayout(
sidebarPanel(
h4("Parámetros"),
textInput("area", "Area"),
textInput("seccion", "Seccion"),
textInput("categoria", "Categoria"),
textInput("per_ant", "Periodo anterior", placeholder="Separadas por comas, Formato AAAAMM"),
textInput("per_act", "Periodo actual", placeholder="Separadas por comas, Formato AAAAMM"),
actionButton("ok", "Generar cuadro")
),
mainPanel(
downloadButton("informe","Guardar Excel"),
tableOutput("ecuacion")
)
)
))
shinyServer(
function(input, output) {
shinyjs::hide("informe")
observeEvent(input$ok,{
id<-showNotification("Ejecutando ...",duration=NULL,closeButton = FALSE,type="message")
nombreinforme<-paste0("Ecuacion_venta_cat", input$categoria, ".csv")
ecuacion_ventas<-ventas(as.integer(input$area),as.integer(input$seccion),as.integer(input$categoria),input$per_ant,input$per_act)
output$ecuacion<-renderTable({
ecuacion_ventas
},rownames = TRUE)
removeNotification(id)
shinyjs::show("informe")
setwd(tempdir())
output$informe<- downloadHandler(
filename = nombreinforme,
content = function(file) {
write.csv2(x = ecuacion_ventas, file = nombreinforme , row.names = TRUE)
})
})
})
Thank you very much,
Naiara.