【发布时间】:2020-11-28 10:37:04
【问题描述】:
我使用 dataTableproxy 编写了我的代码。我的代码的目标是在单击编辑按钮时打开一个弹出窗口。我可以修改弹出窗口中的行。 代码做得很好,即当我编辑一行时,我可以修改它。 现在我想将值保存在我编辑的表中。我尝试使用 coerceValue 但它不起作用。我想我不明白如何将代理中的值返回到我编辑的表中。 你有什么想法或建议吗? 提前致谢
# Global.R
rm(list = ls())
library(DT)
library(shiny)
library(shinydashboard)
library(dplyr)
library(lubridate)
df<-data.frame(
ECR= c("040/19", "050/20"),
BEM=as.Date(c("2020/03/01", "2020/02/01")),
BEE=c("", ""),
FIN=c(4,-5)
)
#ui.R
ui<-fluidPage(
DT::dataTableOutput(outputId ="data.tab"),
actionButton(inputId = "edit",label = "Edit",color="green",class="butt4")
)
# Server.R
server<-function(input, output,session) {
mod_df <- shiny::reactiveValues(x = df)
output$data.tab <- DT::renderDataTable({
DT=df
datatable(DT,selection = 'single',
escape=F,rownames = FALSE)
})
observeEvent(input$edit,
{
showModal(modalDialog(
infoBox("ECR CARD", uiOutput("card"),
icon = icon("line-chart")),
DT::dataTableOutput('tab'),
actionButton("save","Save changes")
))
}
)
output$tab <- DT::renderDT({
selected_row=input$data.tab_rows_selected
mod_df<-mod_df$x[selected_row,]
isolate(mod_df)
#print(mod_df)
}, escape=FALSE,selection = 'none',editable="all",rownames=FALSE
)
val<-eventReactive(input$edit,{
selected_row=input$data.tab_rows_selected
mod_df<-mod_df$x[selected_row,]
mod_df
})
output$card<- renderText({
val.ecr<-val()
prettyNum(paste0(val.ecr[1,1]))
})
proxy <- DT::dataTableProxy('tab')
shiny::observe({DT::replaceData(proxy, mod_df$x)})
#######save - IT'S HERE I DON'T HOW I CAN DO?
observeEvent(input$save,{
})
}
shinyApp(ui, server)
【问题讨论】:
-
也许回答here 可能会有所帮助
-
我检查了您的链接,并尝试重现相同的内容,但它不起作用。我想我没有理解 dataTableproxy 的使用方式。
-
刚刚收到消息。以后大家可以用@YBS开头评论,然后我会收到消息的。让我看看。
-
@YBS.OK!提前感谢您的帮助。
-
抱歉,我无法保存更改,因为它发生在模式对话框中,需要关闭它才能更改表中的值。