繁体   English   中英

单击即可下载数据表中的所有行

[英]Download all rows in the datatable in the single click

在下面的应用程序中,如果我需要下载所有 32 行,我将不得不转到所有页面然后下载,这是非常耗时的。 有没有办法自行下载第一页中的所有行(在第一张表中只保留 10 行)

library(shiny)
library( DT )

# Define UI for application that creates a datatables
ui <- fluidPage(

  # Application title
  titlePanel("Download Datatable")

  # Show a plot of the generated distribution
  , mainPanel(
    DT::dataTableOutput("fancyTable")
  ) # end of main panel

) # end of fluid page

# Define server logic required to create datatable
server <- function(input, output) {

  output$fancyTable <- DT::renderDataTable(
    datatable( data = mtcars
               , extensions = 'Buttons'
               , options = list( 
                 dom = "Blfrtip"
                 , buttons = 
                   list("copy", list(
                     extend = "collection"
                     , buttons = c("csv", "excel", "pdf")
                     , text = "Download"
                   ) ) # end of buttons customization

                 # customize the length menu
                 , lengthMenu = list( c("All") # declare values
                                       # declare titles
                 ) # end of lengthMenu customization
                 , pageLength = 10


               ) # end of options

    ) # end of datatables
  )
} # end of server

# Run the application 
shinyApp(ui = ui, server = server)

您需要在renderDataTable设置参数server = FALSE 这样做的原因是,当server = TRUE这是默认设置时,只有可见的行被传送到小部件。

library(shiny)
library( DT )

# Define UI for application that creates a datatables
ui <- fluidPage(

  # Application title
  titlePanel("Download Datatable")

  # Show a plot of the generated distribution
  , mainPanel(
    DT::dataTableOutput("fancyTable")
  ) # end of main panel

) # end of fluid page

# Define server logic required to create datatable
server <- function(input, output) {

  output$fancyTable <- DT::renderDataTable(
    datatable( data = mtcars
               , extensions = 'Buttons'
               , options = list( 
                 dom = "Blfrtip"
                 , buttons = 
                   list("copy", list(
                     extend = "collection"
                     , buttons = c("csv", "excel", "pdf")
                     , text = "Download"
                   ) ) # end of buttons customization

                 # customize the length menu
                 , lengthMenu = list( c("All") # declare values
                                      # declare titles
                 ) # end of lengthMenu customization
                 , pageLength = 10


               ) # end of options

    ) # end of datatables
  , server = FALSE
  )
} # end of server

# Run the application 
shinyApp(ui = ui, server = server)

希望这可以帮助!!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM