I have this simple script.R which creates an empty Excel file:
my_script <- function() {
data <- data.frame()
write_xlsx(data, "my_excel.xlsx")
}
I called it in the Shiny App with this code:
library(shiny)
source("my_script.R", local=TRUE)
ui <- fluidPage(
tags$h1("New excel file")
actionButton(button, "Make file")
)
server <- function(input, output) {
observeEvent(input$button, {
source("my_script.R")
})
}
shinyApp(ui=ui, server=server)
When I run the app, the title and the button "Make file" appear correctly, but when I click the button, no file is created. I have put my_script.R it in the same directory of app.R. Where am I wrong?
P.s. I have already read these topics ( call R script from Shiny App How can I connect R Script with Shiny app in R? How to execute a long R script as function in RShiny and display the solution in the ui? ), but I couldn't find a solution.
Thanks in advance!