在闪亮的应用程序中选中/取消选中列后,数据表中已编辑的单元格返回其原始值 [英] edited cell in data table goes back to its original value after check/uncheck column in shiny app
本文介绍了在闪亮的应用程序中选中/取消选中列后,数据表中已编辑的单元格返回其原始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是此帖子的扩展
在编辑可编辑数据表中的任何单元格之后,我选中/取消选中某些列,该单元格返回其原始值。
After I edit any cell in the editable data table, I check/uncheck some column, the cell goes back to its original value.
我不知道为什么会这样。有谁知道我该如何解决?
非常感谢!
I have not idea why that happens. Does anyone know how I can fix this? Thank you very much in advance!
library(shiny)
library(DT)
library(dplyr)
# UI
ui = fluidPage(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 %>% select(one_of(input$datacols))
})
# render DT
output$tbl = renderDT(server=FALSE, {
datatable(df$dat,
editable = "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)
推荐答案
渲染数据表时,我们需要选择列。
We need to select columns when we render the datatable.
observe ({
df$dat = iris
})
# render DT
output$tbl = renderDT(server=FALSE, {
datatable(df$dat %>% select(one_of(input$datacols)),
editable = "cell",
extensions = "Buttons",
options = list(
dom = "Bfrtip", buttons = list("csv")))
})
这篇关于在闪亮的应用程序中选中/取消选中列后,数据表中已编辑的单元格返回其原始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文