This is probably doable with the Editor extension but it is not free.
Here is something close, using the KeyTable extension.
library(shiny)
library(DT)
ui <- fluidPage(
DTOutput("table")
)
js <- c(
"table.on('key', function(e, datatable, key, cell, originalEvent){",
" var targetName = originalEvent.target.localName;",
" if(key == 13){",
" if(targetName == 'body'){",
" $(cell.node()).trigger('dblclick.dt');",
" }else if(targetName == 'input'){",
" $(originalEvent.target).trigger('blur');",
" }",
" }",
"})"
)
server <- function(input, output, session){
output$table <- renderDT({
datatable(
iris,
selection = "none",
editable = TRUE,
callback = JS(js),
extensions = "KeyTable",
options = list(
keys = TRUE
)
)
})
}
shinyApp(ui, server)
1) Select a cell:
2) Press Enter to edit the cell:
3) Press Enter when the edit is done, and press Tab to go the next cell:
4) Press Enter to edit the cell:
etc...
This is not so nice as a spreadsheet editor, but this allows to edit the cells with the keyboard only.
You can also use the arrows to navigate between cells.
EDIT
Here is a better solution. Replace js
with
js <- c(
"table.on('key', function(e, datatable, key, cell, originalEvent){",
" var targetName = originalEvent.target.localName;",
" if(key == 13 && targetName == 'body'){",
" $(cell.node()).trigger('dblclick.dt');",
" }",
"});",
"table.on('keydown', function(e){",
" if(e.target.localName == 'input' && [9,13,37,38,39,40].indexOf(e.keyCode) > -1){",
" $(e.target).trigger('blur');",
" }",
"});"
)
Now when you edit a cell you can:
press Enter to validate the edit and stay at the same position;
or press Tab or an arrow key to validate the edit and navigate, and there's no need to press Enter to validate the edit.
EDIT 2
With the code below:
navigate in the table, press Enter to edit;
press Enter to validate the edit and stay at the same position;
if you are editing a cell, then pressing Tab or an arrow key will trigger the edit of the new cell.
.
js <- c(
"table.on('key', function(e, datatable, key, cell, originalEvent){",
" var targetName = originalEvent.target.localName;",
" if(key == 13 && targetName == 'body'){",
" $(cell.node()).trigger('dblclick.dt');",
" }",
"});",
"table.on('keydown', function(e){",
" if(e.target.localName == 'input' && [9,13,37,38,39,40].indexOf(e.keyCode) > -1){",
" $(e.target).trigger('blur');",
" }",
"});",
"table.on('key-focus', function(e, datatable, cell, originalEvent){",
" var targetName = originalEvent.target.localName;",
" var type = originalEvent.type;",
" if(type == 'keydown' && targetName == 'input'){",
" if([9,37,38,39,40].indexOf(originalEvent.keyCode) > -1){",
" $(cell.node()).trigger('dblclick.dt');",
" }",
" }",
"});"
)