R shiny module with save button and tabs

I am setting up a module, with the purpose of having two data tables in the same app, in different tabs. I would like to be able to edit and save each table separately. In my code, only the first "save" button works, and it saves both data tables. Ideally, each save button should work and save only the corresponding table.

Here is my problematic code:

library(shiny)
library(DTedit)

myModuleUI <- function(id,nam) {
  ns <- shiny::NS(id)
  shiny::tagList(
    
    br(),
    
    ##### needs corrections!!
    
    tabsetPanel(tabPanel("XXX",  dteditmodUI(ns(nam)),actionButton(ns("reset"), "Reset to Saved", styleclass = "warning"),  actionButton(ns("saveBtn"), label = "save"),  br(),
                         id=ns('tabset'), type = 'tabs')
    )
  )
  ####
}

myModule <- function(input, output, session,df,nam,taby,wb) {
  
  dfr=reactiveVal()
  dfr(df)
  
  
  Grocery_List_Results <- shiny::callModule(
    dteditmod,
    id = nam,
    thedata =dfr)
    
   

  # ### save  part
  
  savd = data.frame(isolate(dfr()))
  
  observeEvent(input$saveBtn, {
    
    print("Q")
    ## Add worksheets
    st = paste(taby,as.character(unclass(Sys.time())),sep="_")
    addWorksheet(wb, st)
    
    writeData(x = Grocery_List_Results$thedata,
              wb = wb,
              sheet = st)
    
    
    saveWorkbook(wb, "wb.xlsx", overwrite = T)
    
    savd <<- Grocery_List_Results$thedata
    
    
    shinyalert(title = "Saved!", type = "success")
  })
  
  observeEvent(input$reset, {
    dfr(savd)
    print(dfr)
    
    shinyalert(title = "Reset to saved data!", type = "info")
  })
  
  
}






########

ui <- fluidPage(
  h3('Grocery List'),
  myModuleUI('myModule1',nam="groc"),br(),
  myModuleUI('myModule1',nam="groc2")
)

server <- function(input, output, session) {
  
  df= data.frame(
    Buy = c('Tea', 'Biscuits', 'Apples',"Tea","Apples"),
    Quantity = c(7, 2, 5,9,44),
    stringsAsFactors = FALSE
  )
  
  file = "AICs.xlsx"
  wb <- loadWorkbook(file)
  
  
  shiny::callModule(myModule, 'myModule1',nam="groc",df=df,taby="Tea",wb)
  shiny::callModule(myModule, 'myModule1',nam="groc2",df=df,taby="Apples",wb)
}


shinyApp(ui = ui, server = server)

I posted the issue also here:https://stackoverflow.com/questions/63479730/r-shiny-module-with-save-button

Hope for your input! Many thanks!!

Afraid I can't run your code to try it.
I assumed you were using


but I get error
Error in dteditmodUI(ns(nam)) : could not find function "dteditmodUI"

and I don't see mention of dteditmodUI in the github example/demo info

You are right- I am sorry!

I use the modified version of DTedit:

devtools::install_github('DavidPatShuiFong/DTedit@2.2.1')

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.