How to use library(writexl) pakcage to save multiple dataframe with a custmized name

Viewed 2528

I am using the package writexl to save two dataframe into one csv file in R shiny.

And here is part of my code:

library(writexl)
server <- function(input,output){
    filename = function(){
              paste('data.csv')
            },
    content = function(file){
    df1  <- ...
    df2 <- ...
    write_xlsx(list(df1,df2), file) 
        }
      )

this code works for me but do you know how to give a customized sheet name for df1 and df2? I don't want to change the package, would just want to use "write_xlsx", not the "write.xlsx"

2 Answers

Hi I just worked it out:

write_xlsx(list("sheet name1" = df1, "sheet name2" = df2), file)

Just name the data frames in the list and it should work.

write_xlsx(list(df1 = df1, df2 = df2), file)

Related