R DT button for downloading files does not include display tables

Here is a simple example. Suppose I look at a table and I want to load the table excluding the Sepal.Length column.

What should I do? I am trying to output the Sepal.Length column and click on excel, but it still gives me all the data. I do not want it. Is there a way I can manipulate this?

Perhaps I am not familiar with how it works in the backend, after I use the extension to reorder a string or search / filter table, then the downloaded files display the table. So I want something like this when I hide the columns.

This is useful when I have too many columns in a table, and sometimes I don’t need all of them.

library(shiny)
shinyApp(
  ui = fluidPage(DT::dataTableOutput('tbl')),
  server = function(input, output) {
    output$tbl = DT::renderDataTable(
      iris, extensions = "Buttons",
      options = list(dom = "Blfrtip", 
        buttons = list('copy', 'excel', 'print', 'colvis'))
    )
  }
)

I really appreciate your help.

+4
source share
1

input$tbl_columns_selected input$tbl_rows_selected

(NB: DT)
, input$tbl_rows_selected target = 'column'

library(shiny)
library(xlsx)
library(DT)

shinyApp(
  ui = fluidPage(
      DT::dataTableOutput('tbl')
      ,downloadButton("downloadData",label ="Download")
  ),

  server = function(input, output) {
    output$tbl = DT::renderDataTable(iris, selection = list(target = 'row+column'))

    myFilteredData <- reactive({
      df <- iris[input$tbl_rows_selected, input$tbl_columns_selected]
      if (length(input$tbl_columns_selected) == 1) {
        df <- as.data.frame(df)
        colnames(df) <- colnames(iris)[input$tbl_columns_selected]
      }
      df
    })

    output$downloadData <- downloadHandler(
      filename = function() {paste("test.xlsx")},
      content = function(file) {
        write.xlsx(myFilteredData(),file, row.names=FALSE)
      })
  }
)
0

Source: https://habr.com/ru/post/1687837/


All Articles