Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use writexl package to save multiple dataframe with a customized name

Tags:

r

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"

like image 905
YihanBao Avatar asked Nov 16 '25 02:11

YihanBao


2 Answers

Hi I just worked it out:

write_xlsx(list("sheet name1" = df1, "sheet name2" = df2), file)
like image 170
YihanBao Avatar answered Nov 18 '25 20:11

YihanBao


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

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

like image 30
bischrob Avatar answered Nov 18 '25 21:11

bischrob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!