I want to use python function in my function.py file and there is one function called run_xi, which is just to extract data from the database and return a data frame to R. However, this code can be run successfully with data_xi <- data.frame(s = c(1:3),r = c(4:6), x =c(19:21))
but if I replace with the code of using reticulate (showed in the following code), it will fail to generate the csv file, only return me back with a HTML file. Is there any solutions?
library(shiny)
library(reticulate)
library(writexl)
#reticulate::source_python("function.py")
#data_xi <- run_xi(26)
if (interactive()) {
ui <-fluidPage(
downloadButton("downloadData", "Download Metrics Reports")
)
#data_xi <- data.frame(s = c(1:3),r = c(4:6), x =c(19:21)) # uncomment here, code will working
reticulate::source_python("function.py") # not working when try to use python function by reticulate
data_xi <- run_xi(26)# not working when try to use python function by reticulate
server <- function(input,output){
output$downloadData <- downloadHandler(
filename = function(){
paste(Sys.time(), 'site_mtx.xlsx')
},
content = function(file){
write_xlsx(data_xi, file)
}
)
}
shinyApp(ui, server)}