Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shiny 下载DT中选定的行_Shiny_Dt - Fatal编程技术网

Shiny 下载DT中选定的行

Shiny 下载DT中选定的行,shiny,dt,Shiny,Dt,是否有任何方法可以使用按钮下载选定的行扩展名?如果没有,是否有办法在左上方的表格中添加自定义按钮?我知道如何下载选定的行。我发现我们可以添加自定义按钮来选择列() 我添加了2个自定义按钮(在下面的代码中提到) 库(ShinydaShashboard) header不确定您希望下载所选行的格式,但下面是一个基于所选内容存储csv文件的示例(您需要一个downloadButton): 库(闪亮) 图书馆(shinyalert) 图书馆(shinydashboard) 我知道如何下载选定的行。但我想用

是否有任何方法可以使用
按钮下载选定的行
扩展名?如果没有,是否有办法在左上方的表格中添加自定义按钮?我知道如何下载选定的行。我发现我们可以添加自定义按钮来选择列()

我添加了2个自定义按钮(在下面的代码中提到)

库(ShinydaShashboard)

header不确定您希望下载所选行的格式,但下面是一个基于所选内容存储csv文件的示例(您需要一个downloadButton):

库(闪亮)
图书馆(shinyalert)
图书馆(shinydashboard)

我知道如何下载选定的行。但我想用DT的按钮扩展来完成。我希望这样做的原因是-我希望下载按钮显示在表内(而不是表外),请参阅可能的副本
library(shinydashboard)

header <- dashboardHeader(title = 'title')
sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem('dashboard', tabName = 'dashboard', icon = icon('dashboard'))
  )
)
body <- dashboardBody(
 fluidPage(fluidRow(
  column(2,   
      actionButton("downloadData", "Download Selected Rows", icon = icon("download"), 
      style="color: #333; background-color: #FFF; border-color: #333")),
      useShinyalert(),
      column(2,  
      actionButton(inputId = "run", label = "Write Selected Rows to SQL", icon = icon("paper-plane"),
                       style="color: #333; background-color: #FFF; border-color: #333")),
     useShinyalert()
  )),

           box(
             title = 'box', width = NULL, status = 'primary',
             DT::dataTableOutput('table2')  
  )
)

ui<-dashboardPage(header, sidebar, body)

server = function(input, output) {
  output$table2 = DT::renderDataTable(
    iris, options = list(lengthChange = FALSE)
  )
}

shinyApp(ui, server)
library(shiny)
library(shinyalert)
library(shinydashboard)

header <- dashboardHeader(title = 'title')
sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem('dashboard', tabName = 'dashboard', icon = icon('dashboard'))
  )
)
body <- dashboardBody(
  fluidPage(fluidRow(
    column(2,   
           downloadButton("downloadData", "Download Selected Rows", icon = icon("download"), 
                          style="color: #333; background-color: #FFF; border-color: #333")),
    useShinyalert(),
    column(2,  
           actionButton(inputId = "run", label = "Write Selected Rows to SQL", icon = icon("paper-plane"),
                        style="color: #333; background-color: #FFF; border-color: #333")),
    useShinyalert()
  )),
  p(),
  box(
    title = 'box', width = NULL, status = 'primary',
    DT::dataTableOutput('table2')  
  )
)

ui<-dashboardPage(header, sidebar, body)

server = function(input, output) {
  output$table2 = DT::renderDataTable(
    iris, options = list(lengthChange = FALSE)
  )

  output$downloadData <- downloadHandler(
    filename = function() {
      paste0(gsub(" ","_", gsub(":",".", Sys.time())),".csv")
    },
    content = function(file) {
      write.table(iris[input$table2_rows_selected,], file, row.names = FALSE)
    }
  )

}

shinyApp(ui, server)