Skip to content

Instantly share code, notes, and snippets.

@hpeaker
Last active March 15, 2018 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpeaker/705a8420821dea76476e0c7cf5c4b017 to your computer and use it in GitHub Desktop.
Save hpeaker/705a8420821dea76476e0c7cf5c4b017 to your computer and use it in GitHub Desktop.
R shiny app with mousewheel scrollable slider.
library(shiny)
server <- function(input, output, session) {
observe({
n <- input$n
if(is.null(input$n)) {
return()
}
change <- sign(input$dy)
isolate(updateSliderInput(session, "slider", value = input$slider + change))
})
}
library(shiny)
ui <- fluidPage(
includeScript("wheel.js"),
div(class = "shinyScroll",
sliderInput("slider", "Hover and move me with the Mouse Wheel!", min = 0, max = 10, value = 2)
),
div(
"Hovering and scrolling here will do nothing"
),
div(class = "shinyScroll",
"Hovering and scrolling here will also move the slider"
)
)
$(document).ready(function() {
var scrollable = document.getElementsByClassName("shinyScroll");
for(var i = 0; i < scrollable.length; i++) {
scrollable[i].addEventListener("wheel", shinyScroll);
}
var n = 0;
function shinyScroll(event) {
n++;
Shiny.onInputChange("n", n);
Shiny.onInputChange("dy", event.deltaY);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment