Skip to content

Commit ba6480e

Browse files
committed
fix data_editor module
1 parent 2b9fafb commit ba6480e

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

modules/core/data_entry_editor_server.R

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,38 @@ data_entry_editor_server <- function(id, parent.session, config, profile, compon
4141
info<-template_info()
4242

4343
if("tab_editor"%in%menu_tabs()){
44-
removeTab(inputId = "tabbox",
44+
removeTab(inputId = "tabbox_data_editor",
4545
session = parent.session,
4646
target = "tab_editor")
4747
}
4848

4949
tabs_list<-unique(c(menu_tabs(),"tab_editor"))
5050
menu_tabs<-menu_tabs(tabs_list)
5151

52-
appendTab(inputId = "tabbox",
52+
appendTab(inputId = "tabbox_data_editor",
5353
session = parent.session,
5454
select=TRUE,
5555
tabPanel(title=tagList(icon("edit"),"Editor"),
5656
value="tab_editor",
5757
uiOutput(ns("buttons_wrapper")),
5858
br(),
59-
uiOutput(ns("table_wrapper"))
59+
uiOutput(ns("hst_table_wrapper"))
6060

6161
)
6262
)
6363

6464
if(any(!is.na(info$ref))){
6565

6666
if("tab_referentials"%in%menu_tabs()){
67-
removeTab(inputId = "tabbox",
67+
removeTab(inputId = "tabbox_data_editor",
6868
session = parent.session,
6969
target = "tab_referentials")
7070
}
7171

7272
tabs_list<-unique(c(menu_tabs(),"tab_referentials"))
7373
menu_tabs<-menu_tabs(tabs_list)
7474

75-
appendTab(inputId = "tabbox",
75+
appendTab(inputId = "tabbox_data_editor",
7676
session = parent.session,
7777
select=FALSE,
7878
tabPanel(title=tagList(icon("search"),"Referentials"),
@@ -86,15 +86,15 @@ data_entry_editor_server <- function(id, parent.session, config, profile, compon
8686
}
8787

8888
if("tab_templates"%in%menu_tabs()){
89-
removeTab(inputId = "tabbox",
89+
removeTab(inputId = "tabbox_data_editor",
9090
session = parent.session,
9191
target = "tab_templates")
9292
}
9393

9494
tabs_list<-unique(c(menu_tabs(),"tab_templates"))
9595
menu_tabs<-menu_tabs(tabs_list)
9696

97-
appendTab(inputId = "tabbox",
97+
appendTab(inputId = "tabbox_data_editor",
9898
session = parent.session,
9999
select=FALSE,
100100
tabPanel(title=tagList(icon("download"),"Templates"),
@@ -263,7 +263,7 @@ data_entry_editor_server <- function(id, parent.session, config, profile, compon
263263

264264
observeEvent(input$new_data,{
265265
req(input$new_data)
266-
ready<-ready(TRUE)
266+
ready<-ready(TRUE)
267267
})
268268

269269
observeEvent(input$import_data,{
@@ -321,7 +321,7 @@ data_entry_editor_server <- function(id, parent.session, config, profile, compon
321321
req(input$format)
322322
if(!is.null(input$task))if(input$task!="")if(!is.null(input$reporting_entity))if(input$reporting_entity!="")if(!is.null(input$format))if(input$format!=""){
323323
reset<-FALSE
324-
if(!is.null(input$table)){
324+
if(!is.null(input$hst_table)){
325325
reset<-TRUE
326326
showModal(
327327
modalDialog(
@@ -362,7 +362,7 @@ data_entry_editor_server <- function(id, parent.session, config, profile, compon
362362
data_template[1,]<-values_type
363363

364364
empty_row<-empty_row(data_template)
365-
cache_data<-cache_data(data_template[rep(seq_len(nrow(data_template)), 10), ])
365+
cache_data<-cache_data(data_template[rep(seq_len(nrow(data_template)), 5), ])
366366
})
367367
}
368368
})
@@ -408,7 +408,7 @@ data_entry_editor_server <- function(id, parent.session, config, profile, compon
408408
data_template[1,]<-values_type
409409

410410
empty_row<-empty_row(data_template)
411-
cache_data<-cache_data(data_template[rep(seq_len(nrow(data_template)), 10), ])
411+
cache_data(data_template[rep(seq_len(nrow(data_template)), 10), ])
412412
})
413413
}
414414
})
@@ -498,13 +498,13 @@ data_entry_editor_server <- function(id, parent.session, config, profile, compon
498498
sprintf("data_%s_%s_%s.csv",input$task,input$reporting_entity,input$format)
499499
},
500500
content = function(filename) {
501-
data_to_save<-hot_to_r(input$table)
501+
data_to_save<-hot_to_r(input$hst_table)
502502
data_to_save<-as.data.frame(data_to_save)
503503
data_to_load<-data_spec()$standardizeContent(data_to_save)
504504
write.csv(data_to_save, filename,row.names = F)
505505
})
506506

507-
output$table<-renderRHandsontable({
507+
output$hst_table<-rhandsontable::renderRHandsontable({
508508
req(!is.null(cache_data()))
509509
req(ready())
510510

@@ -542,9 +542,11 @@ data_entry_editor_server <- function(id, parent.session, config, profile, compon
542542
cache_report<-cache_report(report)
543543

544544
#display
545-
editable_table<-data_spec()$display_as_handsontable(data, report, read_only = FALSE) %>%
545+
editable_table<-data_spec()$display_as_handsontable(data, as.data.frame(report), read_only = FALSE) %>%
546546
hot_context_menu(allowRowEdit = T, allowColEdit = F)
547547

548+
editable_table
549+
548550
#column that should not be editable --> put them as readonly
549551
info<-template_info()
550552
if(any(!info$editable)){
@@ -565,24 +567,24 @@ data_entry_editor_server <- function(id, parent.session, config, profile, compon
565567
}
566568
}
567569

568-
return(editable_table)
570+
editable_table
569571
})
570572

571573

572574
#observe changes on handsontable
573-
observeEvent(input$table$changes$changes,{
575+
observeEvent(input$hst_table$changes$changes,{
574576
WARN("Triggered handsontable cell event on render")
575-
target_cell_row = input$table$changes$changes[[1]][[1]]+1
576-
target_cell_col = input$table$changes$changes[[1]][[2]]+1
577-
target_cell_value_old = input$table$changes$changes[[1]][[3]]
577+
target_cell_row = input$hst_table$changes$changes[[1]][[1]]+1
578+
target_cell_col = input$hst_table$changes$changes[[1]][[2]]+1
579+
target_cell_value_old = input$hst_table$changes$changes[[1]][[3]]
578580
if(is.null(target_cell_value_old)) target_cell_value_old = ""
579-
target_cell_value_new = input$table$changes$changes[[1]][[4]]
581+
target_cell_value_new = input$hst_table$changes$changes[[1]][[4]]
580582
if(is.null(target_cell_value_new)) target_cell_value_new = ""
581583
if(target_cell_value_old != target_cell_value_new){
582584
WARN("Changed row = %s", target_cell_row)
583585
WARN("Changed col = %s", target_cell_col)
584586
WARN("Value '%s' changed by '%s'", target_cell_value_old, target_cell_value_new)
585-
updated_hst = hot_to_r(input$table) %>% as.data.frame()
587+
updated_hst = hot_to_r(input$hst_table) %>% as.data.frame()
586588

587589
WARN("Caching data...")
588590
WARN("Old data cell content:")
@@ -595,13 +597,13 @@ data_entry_editor_server <- function(id, parent.session, config, profile, compon
595597
}
596598
})
597599

598-
output$table_wrapper<-renderUI({
600+
output$hst_table_wrapper<-renderUI({
599601
req(!is.null(cache_data()))
600602
req(ready())
601603
info<-template_info()
602604
div(
603605
div(
604-
rHandsontableOutput(ns("table"))
606+
rhandsontable::rHandsontableOutput(ns("hst_table"))
605607
),
606608
br(),
607609
div(
@@ -653,7 +655,7 @@ data_entry_editor_server <- function(id, parent.session, config, profile, compon
653655
new_row<-empty_row()
654656
for (i in 1 : input$nb_add_row){
655657
if(i==1){
656-
last_data <- hot_to_r(input$table)
658+
last_data <- hot_to_r(input$hst_table)
657659
}else {
658660
last_data <- new_data
659661
}

0 commit comments

Comments
 (0)