gpt4 book ai didi

r - Shiny 的 DT 数据表 使用户只能编辑某些列

转载 作者:行者123 更新时间:2023-12-04 16:26:03 26 4
gpt4 key购买 nike

一个简单的应用程序:

#
# 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)

使用这一行: disable = list(columns = c(1,2) 我打算使第一列和第二列不可编辑。但是,所有列似乎都是可编辑的: enter image description here

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

最佳答案

根据 DT::datatable() 的文档,editable 参数的结构应该不同:

This argument can also be a list of the form list(target = TARGET,disable = list(columns = INDICES)), where TARGET can be cell, row,column, or all, and INDICES is an integer vector of column indices.

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

关于r - Shiny 的 DT 数据表 使用户只能编辑某些列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63906004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com