Skip to content

Instantly share code, notes, and snippets.

@pepijn-devries
Created June 30, 2017 20:11
Show Gist options
  • Save pepijn-devries/7ccd12df3179873492a7af53d5ea1658 to your computer and use it in GitHub Desktop.
Save pepijn-devries/7ccd12df3179873492a7af53d5ea1658 to your computer and use it in GitHub Desktop.
Trick-event-ui
# This part of the code generates the user interface show at the client's side.
# For details and tutorials go to http://shiny.rstudio.com
ui <- shinyUI(fluidPage(
# This adds a tiny bit of javascript to the client side's web page.
# It defines a global variable 'negator', which is negated when
# the javascript function negate() is called.
# This can be used to trick Shiny's event observers.
tags$head(tags$script("var negator=1;
function negate() {
negator = -negator
return(negator)
}")),
# A custom user interface element:
# If you click me twice in a row, the second time, nothing will happen:
p(a("I'm a custom interface", href = "#",
onclick = "Shiny.onInputChange(\"customInterface\", 1);"),
"clicking me twice won't work as intended..."),
# Another custom user interface element:
# If you click me twice in a row, the siny server will respond (because
# the value that is being passed is negated):
p(a("I'm another custom interface", href = "#",
onclick = "Shiny.onInputChange(\"customInterface\", 2*negate());"),
"clicking me twice will work as intended..."),
# Output text will be shown here:
verbatimTextOutput("outputText"),
p("Source code is shown below")
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment