Created
November 6, 2016 17:19
-
-
Save jlitven/da5572fb09de9709f2626580eebc920a to your computer and use it in GitHub Desktop.
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
# Javascript functions to set audio source, play and pause the audio | |
js_set_audio_src = "shinyjs.setAudioSrc = function(source){document.getElementById('audio_player').src=source};" | |
js_pause_audio = "shinyjs.pauseAudio = function(){document.getElementById('audio_player').pause()};" | |
js_play_audio = "shinyjs.playAudio = function(){document.getElementById('audio_player').play()};" | |
# Values stores the last point so we can turn off the audio | |
Values<-reactiveValues(old="Start") | |
# Preview the track when the user clicks on the graph point | |
# Pause the track if it's the same point | |
observe({ | |
if(length(input$tooltip)==0){ | |
return() | |
} | |
if(input$tooltip != ""){ | |
full_name = unlist(strsplit(input$tooltip,split = "<br>"))[1] | |
if(isolate({input$tooltip == Values$old})){ | |
js$playAudio() | |
}else{ | |
preview_url = tracks[tracks$full_name==full_name, 'preview_url'] | |
js$setAudioSrc(preview_url) | |
isolate({ Values$old<-input$tooltip }) | |
} | |
}else{ | |
js$pauseAudio() | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment