我使用以下代码将 excel 文件上传到闪亮的 R 中:
服务器.r
#reative function to read a table
MDPData<-reactive({
file1<-input$MDPhistorical
if(is.null(file1)){return()}
z<-as.data.frame(read.xlsx(file1$datapath,sheetName = 'Probability Matrix'))
})
#file info
output$MDPDataTable<-DT::renderDataTable({
if(is.null(MDPData())){return()}
MDPData()
DT::datatable(MDPData(),extensions = 'Responsive', options = list(pageLength=3), class = 'cell-border stripe', selection = "single")
})
ui.r 的相关代码:
fluidRow(
box(
title = "Historical Data of different conditions", status = "primary", solidHeader = TRUE,
collapsible = TRUE,
DT::dataTableOutput("MDPDataTable")
)
)
然后我想将 MDPDataTable 保存为 csv 文件。我尝试使用 write.csv :
write.xlsx(MDPDataTable,'www/probabilitymatrix.csv')
错误如下:
Warning: Error in is.data.frame: object 'MDPDataTable' not found
Stack trace (innermost first):
42: is.data.frame
41: write.xlsx
40: server [C:\Users\foad\Desktop\DSS Journal\NSS Protorype\Nss-28-2-17/server.R#902]
1: shiny::runApp
Error in is.data.frame(x) : object 'MDPDataTable' not found