在R中编辑DataTable的特定列

问题描述 投票:3回答:1

我试图使用editable = TRUE编辑r中的DataTable。但是,我想只编辑表的某些特定列而不是所有列。那可能吗?我使用的代码是:

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)
r datatable multiple-columns edit
1个回答
0
投票

也许有点晚了,但我尝试了同样的方法,只通过制作一个if语句找到了解决问题的方法,例如,如果你只想更改第3列:

if(j == 3){
    data[i, j] <<- DT::coerceValue(v, data[i, j])
    replaceData(proxy, data, resetPaging = FALSE)
}else{}

至少它适用于我,但我更愿意处理它不同。

© www.soinside.com 2019 - 2024. All rights reserved.