Your solution works. However, it is also possible to use jQuery UI's power to control that. You can also use the options
argument of the jqui_sortable
function to control scrolling and much more of the interactions of jQuery Widgets, documented here. The sortable options are listed here, from which we find, scroll, scrollSensitivity, scrollSpeed, which are options and sort, which controls the events of sorting.
To do what you want in javaScript is like this:
$(".sortable").sortable({
scroll: true,
scrollSensitivity: 40,
scrollSpeed: 1,[
sort: function(event, ui) {
var currentScrollTop = $(window).scrollTop(),
topHelper = ui.position.top,
delta = topHelper - currentScrollTop;
setTimeout(function() {
$(window).scrollTop(currentScrollTop + delta);
}, 5);
}
});
We can define these options in shinyjqui like so:
jqui_sortable("#lst", operation = "enable", options = list(
scroll = TRUE,
scrollSensitivity = 40,
scrollSpeed = 1,
sort = JS('function(event, ui) {
var currentScrollTop = $(window).scrollTop(),
topHelper = ui.position.top,
delta = topHelper - currentScrollTop;
setTimeout(function() {
$(window).scrollTop(currentScrollTop + delta);
}, 5);
}'))
)
Notice I've simply set the scroll, scrollSpeed and scrollSensitivity as items in a list. The sort requires a function, as can be seen in the function above, as well as in the documentation:
sort( event, ui )
This then gives us the scroll:

The benefit of this approach is you can enable or disable scroll, control scroll speed, scroll sensitivity (how close to the edge should the scroll start). For instance, with your solution I can disable scrolling by setting scroll = FALSE and it doesn't scroll. There many more interactions not just scrolling, which is what makes jQuery UI so great! I recommend this approach to take full advantage of jQuery UI.
Full App:
library(shiny)
library(shinyjqui)
ui <- dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
actionButton("add", "add"),
div(id = "lst"),
))
server <- function(input, output, session) {
observeEvent(input$add, {
jqui_sortable("#lst", operation = "destroy")
insertUI(
selector = "#lst",
where = "beforeEnd",
ui = fluidRow(box(title = paste0("test", input$add), h1("test")))
)
jqui_sortable("#lst", operation = "enable", options = list(
scroll = TRUE,
scrollSensitivity = 40,
scrollSpeed = 1,
sort = JS('function(event, ui) {
var currentScrollTop = $(window).scrollTop(),
topHelper = ui.position.top,
delta = topHelper - currentScrollTop;
setTimeout(function() {
$(window).scrollTop(currentScrollTop + delta);
}, 5);
}'))
)
})
}
shinyApp(ui, server)