r - 在闪亮的应用程序中编辑后数据表消失
问题描述
我正在尝试在闪亮的应用程序中制作可编辑和可下载的数据表。在我编辑表格后,数据表格由于某种原因自动消失了。这只发生在数据dat
是反应性的(这在我的应用程序中是必需的)时。
有谁知道发生了什么?非常感谢。
下面的示例代码:
library(shiny)
library(DT)
ui <- fluidPage(
selectInput("nrow",
"num of rows",
choices = 1:5,
selected = 3,
multiple = FALSE),
DTOutput("table")
)
server <- function(input, output){
dat = reactive({
iris[1:as.integer(input$nrow),]
})
output[["table"]] <- renderDT({
datatable(dat(), editable = "cell", extensions = "Buttons",
options = list(
dom = "Bfrtip",
buttons = list(
"csv"
)
))
})
observeEvent(input[["table_cell_edit"]], {
cellinfo <- input[["table_cell_edit"]]
dat() <<- editData(dat(), input[["table_cell_edit"]], "table")
})
}
shinyApp(ui, server)
解决方案
尝试这个:
library(shiny)
library(DT)
ui <- fluidPage(
selectInput("nrow","num of rows",choices = 1:5,selected = 3,multiple = FALSE),
DTOutput("table")
)
server <- function(input, output){
v <- reactiveValues()
observeEvent(input$nrow,{
v$dat <- iris[1:as.integer(input$nrow),]
})
output[["table"]] <- renderDT({
datatable(v$dat, editable = "cell", extensions = "Buttons", options = list(dom = "Bfrtip",buttons = list("excel")))
})
observeEvent(input[["table_cell_edit"]], {
cellinfo <- input[["table_cell_edit"]]
v$dat <<- editData(v$dat, input[["table_cell_edit"]], "table")
})
}
shinyApp(ui, server)
推荐阅读
- java - 反应循环中的数据库插入
- css - CSS Sticky - 如何粘在一边以填充可用高度?
- angular - 如何将深层嵌套对象转换为可观察对象,然后将其拔出
- java - 如何在spring boot中删除行
- javascript - Vue.js排序数组让页面跳转到顶部
- android - 如何从另一个类/静态上下文访问 android 字符串资源?
- java - Junit 5 找实际环境配置运行测试
- c - strncpy 的第三个参数改变了我的局部变量
- java - Flowable服务任务中的Spring bean注入问题
- python - TypeError:render_template() 采用 1 个位置参数,但在(Flask 框架)中给出了 2 个