闪亮的 DT 数据表使用户只能编辑某些列

Dou*_*Fir 2 r shiny dt

一个简单的应用程序:

#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(

    # Application title
    titlePanel("blah"),

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(),

        # Show a plot of the generated distribution
        mainPanel(
            DT::DTOutput('ex_df')
        )
    )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
    
    output$ex_df <- DT::renderDT(data.frame(
        x = 1:10,
        y = 1,
        z = 11:20
    ), 
    
    selection = 'none', editable = 'cell', server = TRUE, rownames = FALSE,
    list(target = 'cell', disable = list(columns = c(1,2)))
    )
}

# Run the application 
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

用这一行:disable = list(columns = c(1,2)我打算使第一列和第二列不可编辑。但是,所有列似乎都是可编辑的: 在此处输入图片说明

如何设置它以便只有第 3 列可编辑?

bca*_*sen 6

根据 的文档DT::datatable()editable论点的结构应该不同:

此参数也可以是 list(target = TARGET, disable = list(columns = INDICES)) 形式的列表,其中 TARGET 可以是单元格、行、列或全部,而 INDICES 是列索引的整数向量。

尝试 editable = list(target = "column", disable = list(columns = c(1,2))