我想在我的function.py文件中使用python函数,有一个名为run_xi的函数,它只是从数据库中提取数据并返回一个数据帧给R。然而,这段代码可以用data_xi <- data.frame(s = c(1:3),r = c(4:6), x =c(19:21))成功运行,但如果我用reticulate的代码(如下面的代码所示)替换,它将无法生成csv文件,只返回一个HTML文件。有什么解决方案吗?
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)}发布于 2020-06-14 12:21:25
我已经解决了这个问题,我使用网状函数创建了另一个R函数来导入python函数,然后在服务器中使用source直接导入r函数,然后它可以作为Excel而不是html下载
https://stackoverflow.com/questions/62368103
复制相似问题