如何从 excelR 包中下载表格?我想使用 excelR 包的原因是用户可以直接输入值,但如果要添加更多而不是几行,我想给他们下载列表的选项。
请参阅下面的最低可重现代码。运行以下代码并单击下载按钮时,它给了我一条错误消息Warning: Error in as.data.frame.default: cannot coerce class ‘c("jexcel", "htmlwidget")’ to a data.frame [No stack trace available]
library(shiny)
library(excelR)
ui <- fluidPage(
fluidRow(
column(6,
titlePanel("Template")
),
column(2,
downloadButton("download1", "Download Template")
)
),
fluidRow(
excelOutput("template2"))
)
server <- function(input, output, session) {
core_data = reactive({
data.frame(Session_Name = rep("",10),
Description1="", Description2="",
Weeks_per_year="",
Patients_per_clinic="")
})
core_columns = reactive({
data.frame(title=c('Session_Name','Description1',
'Description2',"Weeks_per_year",
"Patients_per_clinic"),
width= c(300,300,100,100,100),
type=c('text','text','text',"numeric","numeric"))
})
core_df = reactive({
excelTable(data=core_data(), columns = core_columns())
})
output$template2 <- renderExcel({
core_df()
})
output$download1 <- downloadHandler(
filename = function(){"user_template.csv"},
content = function(file){
write.csv(core_df(), file,row.names = FALSE)
}
)
}
shinyApp(ui, server)
