如何在闪亮的可编辑数据表中指定文件名并限制列编辑

zes*_*sla 1 r shiny dt

我这里有一个闪亮的应用程序示例。它使用包显示可编辑的DT数据表。

为了能够下载多个页面上显示的所有数据,我server=FALSE与 一起使用renderDT

我现在想要实现的是

  1. 限制用户编辑某些特定列。下面的代码似乎不起作用。

    editable = list(target = 'cell', disable = list(column = c("Sepal.Length", "Sepal.Width")))

  2. 我想在导出到 csv 时指定默认文件名,例如 data.csv. 那可能吗?

如果有人能帮助我,我将非常感激。多谢。

    library(shiny)
    library(DT)
    library(dplyr)    
    # UI
    ui = fluidPage(
        selectInput("nrows",
                    "select n entries",
                    choices = 100:150,
                    selected = 100,
                    multiple = FALSE),
        DT::dataTableOutput('tbl'),
                   checkboxGroupInput('datacols', 
                                      label='Select Columns:',
                                      choices= c('Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width', 'Specie'),
                                      selected = c('Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width', 'Specie'),
                                      inline=TRUE )

    )

    # SERVER
    server = function(input, output) {



        df = reactiveValues()
        observe ({

            df$dat = iris %>% .[1:input$nrows, ]

        })

        # render DT
        output$tbl = renderDT(server=FALSE, {
            datatable(df$dat %>% select(one_of(input$datacols)),
                      editable = list(target = 'cell', disable = list(column = c("Sepal.Length", "Sepal.Width"))),  #"cell",
                      extensions = "Buttons",
                      options = list(
                          dom = "Bfrtip", buttons = list("csv")))

        })


        observeEvent(input[["tbl_cell_edit"]], {
            cellinfo <- input[["tbl_cell_edit"]]
            df$dat  <- editData(df$dat,  input[["tbl_cell_edit"]])
        })

    }
    shinyApp(ui=ui, server = server)
Run Code Online (Sandbox Code Playgroud)

Sté*_*ent 5

要禁用某些列的编辑,您必须提供列索引,而不是列名称。此外,关键词是columns,而不是column

editable = list(target = 'cell', disable = list(columns = c(1,2)))
Run Code Online (Sandbox Code Playgroud)

要指定文件名,请执行以下操作:

        buttons = list(
          list(extend = "csv", text = "Export to CSV", filename = "iris")
        )
Run Code Online (Sandbox Code Playgroud)