Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have code as following in shiny

DT::renderDataTable({ 
  df()
  , rownames=FALSE
  ,extensions = c('Responsive', 'Buttons')
  , options = list(
    # dom = 'C<"clear">T<"clear">lfrtip'
    # , tableTools=list(sSwfPath = copySWF('www'))
    dom = 'Bfrtip'
    , buttons = c('pageLength'
                  , 'colvis'
                  , 'pdf')
    , orientation ='landscape'
    , lengthMenu = list(c(6, 12, 18, -1), c('6', '12', '18', 'All'))
    , pageLength = 12
    )
  )
}
})

I want to download pdf in landscape. How should I do it.

According to following link: https://datatables.net/reference/button/pdf that we can pass orientation as landscape. However, I am not able to do it.

I have tried following:

DT::renderDataTable({ 
  df()
  , rownames=FALSE
  ,extensions = c('Responsive', 'Buttons')
  , options = list(
    # dom = 'C<"clear">T<"clear">lfrtip'
    # , tableTools=list(sSwfPath = copySWF('www'))
    dom = 'Bfrtip'
    , buttons = c('pageLength'
                  , 'colvis'
                  , list(extend: 'pdf', orientation='landscape')
    , orientation ='landscape'
    , lengthMenu = list(c(6, 12, 18, -1), c('6', '12', '18', 'All'))
    , pageLength = 12
    )
  )
}
})
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
694 views
Welcome To Ask or Share your Answers For Others

1 Answer

This works for me. Since you didn't provide the data I used the iris dataset. Not the the pdf is in landscape orientation but the table does not use all the available space, but the behavior is the same as in the datatables example. It does not work from RStudio, but it does in the browser (Firefox 49.0)

This is the code:

    library(shiny)
    library(DT)

    shinyApp(
            ui = fluidPage(DT::dataTableOutput('tbl')),
            server = function(input, output) {
                    output$tbl = DT::renderDataTable(
                            datatable(
                                    iris,
                                    rownames = FALSE,
                                    extensions = c('Responsive', 'Buttons'), options = list(
                                            pageLength = 12,
                                            orientation ='landscape',
                                            lengthMenu = list(c(6, 12, 18, -1), c('6', '12', '18', 'All')),
                                            dom = 'Bfrtip',
                                            buttons = 
                                                    list('pageLength', 'colvis', list(
                                                            extend = 'pdf',
                                                            pageSize = 'A4',
                                                            orientation = 'landscape',
                                                            filename = 'tt'


                                                    ))

                                    ))
                    )
            }
    )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...