Created
October 17, 2013 17:22
-
-
Save hinkelman/7028850 to your computer and use it in GitHub Desktop.
Demo of problem with renderUI and animation 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) | |
grp <- c(rep("A", 900), rep("B", 1200)) | |
# Define server logic for slider examples | |
shinyServer(function(input, output) { | |
sub <- reactive({ | |
grp[grp %in% input$group] | |
}) | |
output$animationControl <- renderUI({ | |
s <- length(sub()) | |
sliderInput(inputId = "animation", | |
label = "renderUI animation", | |
min = 1, | |
max = s, | |
value = 1, | |
step = 1, | |
animate=animationOptions(interval=300, loop=F) | |
) | |
}) | |
# Reactive expression to compose a data frame containing all of the values | |
sliderValues <- reactive({ | |
if (is.null(input$animation)){return(NULL)} | |
# Compose data frame | |
data.frame( | |
Name = c("Integer", | |
"Decimal", | |
"Range", | |
"Custom Format", | |
"Animation"), | |
Value = as.character(c(input$integer, | |
input$decimal, | |
paste(input$range, collapse=' '), | |
input$format, | |
input$animation)), | |
stringsAsFactors=FALSE) | |
}) | |
# Show the values using an HTML table | |
output$values <- renderTable({ | |
sliderValues() | |
}) | |
}) |
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) | |
# Define UI for slider demo application | |
shinyUI(pageWithSidebar( | |
# Application title | |
headerPanel("Sliders"), | |
# Sidebar with sliders that demonstrate various available options | |
sidebarPanel( | |
# Simple integer interval | |
sliderInput("integer", "Integer:", | |
min=0, max=1000, value=500), | |
# Decimal interval with step value | |
sliderInput("decimal", "Decimal:", | |
min = 0, max = 1, value = 0.5, step= 0.1), | |
# Specification of range within an interval | |
sliderInput("range", "Range:", | |
min = 1, max = 1000, value = c(200,500)), | |
# Provide a custom currency format for value display, with basic animation | |
sliderInput("format", "Custom Format:", | |
min = 0, max = 10000, value = 0, step = 2500, | |
format="$#,##0", locale="us", animate=TRUE), | |
# Animation with custom interval (in ms) to control speed, plus looping | |
# sliderInput("animation", "Looping Animation:", 1, 2100, 1, step = 10, | |
# animate=animationOptions(interval=300, loop=FALSE)), | |
wellPanel( | |
checkboxGroupInput("group", "Group", | |
list("A", "B"), | |
selected = c("A", "B") | |
), | |
uiOutput("animationControl") | |
) | |
), | |
# Show a table summarizing the values entered | |
mainPanel( | |
tableOutput("values") | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment