Last active
March 15, 2018 17:24
-
-
Save hpeaker/705a8420821dea76476e0c7cf5c4b017 to your computer and use it in GitHub Desktop.
R shiny app with mousewheel scrollable slider.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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