【发布时间】:2020-03-27 22:18:42
【问题描述】:
这个用R shiny 下载对象真的让我很头疼,尽管它看起来太简单了,但我不知道如何继续下去。这个问题旨在将formattable 输出下载为excel 表,但我什至不确定它们是否兼容,或者图像可能会很好。 @ 987654322@ 在我编写代码时似乎需要做一些事情,但是当我设置它时,每个用于绘图的 dowloadButton 问题都将绘图输入与输出分开,但它并没有像我想象的那样工作,所以我可以'甚至继续检查我的下载按钮是否可以工作。任何想法或路径都将不胜感激!
library(openxlsx)
library(shiny)
library(formattable)
ui <- fluidPage(
fluidRow(
sidebarPanel(
hr(style="border-color: #606060;"),
# Add bullets
h3(HTML(paste0("<b>","Download","</b>"))),
downloadButton(outputId = "table_dowload",
label = "Download"),
hr(style="border-color: #606060;"),
width = 3
),
mainPanel(
br(),
formattableOutput("info_company_table"),
br()
)
)
)
server <- function(input, output, session) {
## Visualization input
table_input <- function(){
bycompany <- structure(list(Parent = "Melissa",
Active = 12681L,
Claims = 16.22,
Strength = 24.15,
Backward = 6.37,
Forward = 1.09),
row.names = 1L,
class = "data.frame")
# Visualize top 10
if(nrow(bycompany())>0) {
t <- formattable(bycompany() %>%
arrange(desc(`Active`, )) %>%
slice(1:10),
align = "l",
list(
`Backward` = color_tile("white", "lightblue"),
`Forward` = color_tile("white", "lightblue"),
`Claims` = color_tile("white", "lightblue"),
`Strength` = color_tile("white", "lightblue"),
`Active` = color_tile("white", "lightblue")
))
} else {
t <- formattable(data.frame())
}
}
## Visualization
output$table <- renderFormattable({
table_input()
})
# DOWNLOAD
output$table_dowload <- downloadHandler(
filename <- function(){
paste("Table",
Sys.Date(),
"xlsx",
sep = ".")
},
content = function(file) {
write.xlsx(table_input(), file)
})
}
shinyApp(ui,server)
【问题讨论】:
标签: r shiny download formattable