Last active
February 1, 2016 00:16
-
-
Save daattali/b95fe2376c9e16f35f15 to your computer and use it in GitHub Desktop.
Little shiny apps used in my shinyjs tutorial http://bit.ly/shinyjs-slides
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
# See http://daattali.com/shiny/colourInput/ for more demos | |
library(shiny) | |
library(shinyjs) | |
ui <- fluidPage( | |
useShinyjs(), | |
colourInput("col", "Colour", "blue") | |
# colourInput("col", "Colour", "#ff0000", | |
# palette = "limited", showColour = "background") | |
) | |
server <- function(input, output, session) { | |
observe({ | |
cat(input$col, "\n") | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
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
# See http://daattali.com/shiny/shinyjs-demo/ for more demos | |
library(shiny) | |
library(shinyjs) | |
ui <- fluidPage( | |
useShinyjs(), | |
actionButton("btn", "Hide"), | |
textInput("text", "Text") | |
) | |
server <- function(input, output) { | |
observeEvent(input$btn, { | |
hide("text") | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
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
# See http://daattali.com/shiny/shinyjs-demo/ for more demos | |
library(shiny) | |
library(shinyjs) | |
ui <- fluidPage( | |
useShinyjs(), | |
actionButton("btn", "Hide"), | |
actionButton("btn2", "Show"), | |
textInput("text", "Text") | |
) | |
server <- function(input, output) { | |
observeEvent(input$btn, { | |
hide("text") | |
}) | |
observeEvent(input$btn2, { | |
show("text") | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
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) | |
library(shinyjs) | |
ui <- fluidPage( | |
useShinyjs(), | |
inlineCSS("#error { color: red; }"), | |
div(id = "form", | |
textInput("name", "Name:", "Dean"), | |
numericInput("age", "Age:", 27), | |
checkboxInput("terms", "I agree to the terms and conditions", FALSE), | |
actionButton("submit", "Submit") | |
), | |
hidden( | |
span(id = "error", | |
"Error:", | |
span(id = "errormsg") | |
), | |
h3(id = "thankyou", "Thank you") | |
) | |
) | |
server <- function(input, output, session) { | |
observe({ | |
toggleState(id = "submit", condition = (input$terms && nzchar(input$name))) | |
}) | |
observeEvent(input$submit, { | |
hide("error") | |
hide("thankyou") | |
if (input$age < 13) { | |
show("error") | |
html("errormsg", "Sorry, we don't like kids") | |
logjs("For undisclosed reasons, we don't allow anyone under the age of 13") | |
return() | |
} | |
reset("form") | |
show("thankyou") | |
delay(2000, hide("thankyou", anim = TRUE, animType = "fade")) | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
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
--- | |
runtime: shiny | |
--- | |
```{r, echo=FALSE} | |
library(shinyjs) | |
useShinyjs(rmd = TRUE) | |
actionButton("button", "Click me") | |
div(id = "hello", "Hello!") | |
observeEvent(input$button, { | |
toggle("hello") | |
}) | |
``` | |
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) | |
library(shinyjs) | |
jscode <- ' | |
shinyjs.foo = function(params) { | |
alert(params); | |
} | |
' | |
ui <- fluidPage( | |
useShinyjs(), | |
extendShinyjs(text = jscode), | |
textInput("text", "Text"), | |
actionButton("btn", "Go") | |
) | |
server <- function(input, output, session) { | |
observeEvent(input$btn, { | |
js$foo(input$text) | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
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) | |
library(shinyjs) | |
jscode <- ' | |
shinyjs.foo = function(params) { | |
var defaultParams = { | |
name : "Dean", | |
age : 27 | |
} | |
params = shinyjs.getParams(params, defaultParams); | |
alert(params.name + " is " + params.age); | |
} | |
' | |
ui <- fluidPage( | |
useShinyjs(), | |
extendShinyjs(text = jscode), | |
textInput("name", "Name", "Dean"), | |
numericInput("age", "Age", 27), | |
actionButton("btn", "Go") | |
) | |
server <- function(input, output, session) { | |
observeEvent(input$btn, { | |
js$foo(age = input$age, name = input$name) | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment