在R中编辑DataTable的特定列
我试图使用editable=TRUE来编辑r中的数据表。 但是,我只想编辑表中的某些特定列,而不是所有列。可能吗? 我使用的代码是:在R中编辑DataTable的特定列,r,datatable,multiple-columns,edit,R,Datatable,Multiple Columns,Edit,我试图使用editable=TRUE来编辑r中的数据表。 但是,我只想编辑表中的某些特定列,而不是所有列。可能吗? 我使用的代码是: library(shiny) library(DT) ui <- fluidPage( DT::dataTableOutput('population_table'), textOutput("text") ) server <- function(input, output, session) { data = head(iris) y <-
library(shiny)
library(DT)
ui <- fluidPage(
DT::dataTableOutput('population_table'),
textOutput("text")
)
server <- function(input, output, session) {
data = head(iris)
y <- reactive({
input$population_table_cell_edit
data
})
output$population_table = DT::renderDataTable(data, selection = 'none',
editable = TRUE)
proxy = dataTableProxy('population_table')
observeEvent(input$population_table_cell_edit, {
info = input$population_table_cell_edit
str(info) #print
i = info$row
j = info$col
v = info$value
data[i, j] <<- DT::coerceValue(v, data[i, j])
replaceData(proxy, data, resetPaging = FALSE)
})
output$text <- renderText({
y()[1, 1]
})
}
shinyApp(ui,server)
库(闪亮)
图书馆(DT)
ui可能有点晚了,但我尝试了同样的方法,只通过使用if语句找到了解决问题的方法,例如,如果您只想更改第3列:
if(j == 3){
data[i, j] <<- DT::coerceValue(v, data[i, j])
replaceData(proxy, data, resetPaging = FALSE)
}else{}
if(j==3){
数据[i,j]