Hello,
Following the different remark from nirgrahamuk of the message here, I made my code with dataTableproxy.
The code is well done, i.e. when I edit a line I can modify it.
Now I would like to save the values in the table I edited. I tried with coerceValue but it doesn't work. I think I didn't understand how to return the values from the proxy to the table I edited.
Do you have an idea or some advice?
Thanks in advance
# global.R
#
rm(list = ls())
library(DT)
library(shiny)
library(shinydashboard)
library(dashboardthemes)
library(dplyr)
library(lubridate)
#ui.R
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<-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
observeEvent(input$save,{
})
}
shinyApp(ui, server)