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

Categories

0 votes
682 views
in Technique[技术] by (71.8m points)

r - shiny datatable in landscape orientation

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

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

1 Answer

0 votes
by (71.8m points)

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'


                                                    ))

                                    ))
                    )
            }
    )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...