我们如何将工作簿保存在某个文件夹中并使其可供用户下载?
ref: Shiny + downloadHandler + Openxlsx 不生成 xlsx 文件
程序:
即使工作簿已写入文件夹,下载该工作簿也会出错。
library(shiny)
library(openxlsx)
library(writexl)
library(tidyverse)
ui <- fluidPage(
downloadButton("dl", "Download")
)
server <- function(input, output) {
data1 = mtcars[,c(1,2)] %>% head() # data for Col 1 ,until Row 6
data2 = gapminder::gapminder[,c(1,4)] %>% head() # data for Col 1 , Row from 8 until Row 13
data3 = mtcars[,c(1,2)] %>% tail() # data for Col 1 , Row from 15 until Row 20
# …Run Code Online (Sandbox Code Playgroud) 我们如何将数据从 Shiny 下载到命名每个工作表的多个工作表上?
比如下面ginberg把mtcars数据保存在sheet1中,我们可以把head(mtcars)保存在sheet2中吗?此外,我们可以不同地命名这些工作表,例如 sheet_data、sheet_head
参考:https : //community.rstudio.com/t/r-shiny-to-download-xlsx-file/18441/3 代码来自https://community.rstudio.com/u/ginberg
library(writexl)
ui <- fluidPage(
downloadButton("dl", "Download")
)
server <- function(input, output) {
data <- mtcars
output$dl <- downloadHandler(
filename = function() { "ae.xlsx"},
content = function(file) {write_xlsx(data, path = file)}
)
### Trial 1
# output$dl <- downloadHandler(
# filename = function() { "ae.xlsx"},
# content = function(file) {
# fname <- paste(file,"xlsx",sep=".")
# wb <- loadWorkbook(fname, create = T)#createWorkbook()
# createSheet(wb, name = "data")
# writeWorksheet(wb, head(mtcars), sheet …Run Code Online (Sandbox Code Playgroud) 我们曾经使用浏览器检查反应值,但是当 ggplot 未呈现预期图形时,我们如何在反应模式下调试它?
library(shiny)
ui <- basicPage(
plotOutput("plot1", click = "plot_click"),
verbatimTextOutput("info")
)
server <- function(input, output) {
output$plot1 <- renderPlot({
browser() # Here, the browser stops but when run the below line, cannot see the plot in plots tab
plot(mtcars$wt, mtcars$mpg) # or ggplot ...both not rendering plot in browser mode
})
output$info <- renderText({
paste0("x=", input$plot_click$x, "\ny=", input$plot_click$y)
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)