如何解决在闪亮的数据表中过滤后导出 xlsx
我尝试导出已在 dataTableOutput 中过滤的数据表。 但是我拿不到修改后的数据表。
在 server.R 中
function(input,output) {
output$lesdoublons <- DT::renderDataTable(
DT::datatable({
MyLittleDataTable <- MYDATATABLE
MyLittleDataTable <- MyLittleDataTable[MyLittleDataTable$Mandant %in% input$mand,]
MyLittleDataTable},filter = 'top',)
)
output$downloadData <- downloadHandler(
filename = "myFile.xlsx",content = function(file) {
wb <- createWorkbook()
sheet_1 <- createSheet(wb,"Liste_doublons")
addDataFrame(
MyLittleDataTable,# Here i can put MYDATATABLE but i want MyLittleDataTable :-(
row.names = FALSE
)
saveWorkbook(wb,file)
}
) # thank you for your help
}
解决方法
当然,我们可以将过滤后的数据帧存储为反应式数据帧。这意味着我们只需过滤一次,然后我们就可以在多个地方使用它。
下面的最小示例向我们展示了从一个较大的数据帧创建一个小的、过滤的数据帧。然后在表格中使用该小数据框并作为下载。
library(shiny)
ui <- fluidPage(
#Dropdown
selectInput("mydropdown","mydropdown",choices = unique(PlantGrowth$group)),#Download
downloadButton("mydownloadbutton","mydownloadbutton"),#Table
tableOutput("mytable")
)
server <- function(input,output,session) {
#My big dataframe (using the inbuilt plantgrowth dataframe)
mydatabig <- PlantGrowth
#My small,filtered dataframe,stored as a reactive dataframe
mydatasmall <- reactive({
mydatabig[mydatabig$group == input$mydropdown,]
})
#Download (using small,filtered dataframe)
output$mydownloadbutton <- downloadHandler(
filename = function() {'mydatasmall.csv'},content = function(file) {write.csv(mydatasmall(),file,row.names = FALSE)}
)
#Table (using small,filtered dataframe)
output$mytable <- renderTable({
mydatasmall()
})
}
shinyApp(ui,server)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。