Created
January 28, 2014 22:03
-
-
Save ptoche/8677460 to your computer and use it in GitHub Desktop.
Demo in Progress (very buggy) on sliderInput with numericInput for min/max
This file contains hidden or 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
# server.R | |
library("shiny") | |
shinyServer( | |
function(input, output, session) { | |
# Reactive slider | |
v <- reactiveValues(min = -5, max = +5, status = 0) | |
observe({ | |
input$sliderMin | |
v$min <- isolate(input$sliderMin) | |
}) | |
observe({ | |
input$sliderMax | |
v$max <- isolate(input$sliderMax) | |
}) | |
# reactive slider | |
slider <- reactive({ | |
if (is.null(input$sliderMin) || is.na(input$sliderMin)) { | |
min <- -5 | |
} else { | |
min <- isolate(input$sliderMin) | |
} | |
if (is.null(input$sliderMax) || is.na(input$sliderMax)) { | |
max <- +5 | |
} else { | |
max <- isolate(input$sliderMax) | |
} | |
Id <- paste0("Id",sample(1:100000,1,replace=TRUE)) # unique Id needed? | |
value <- ((min+max)/2) | |
if (!(min < max) || !(is.numeric(min)) || !(is.numeric(max))) { | |
return(list(min=-5, max=+5, Id=Id, value=0)) | |
} else { | |
return(list(min=min, max=max, Id=Id, value=value)) | |
} | |
}) | |
# output slider | |
output$sliderUI <- renderUI({ | |
list( | |
sliderInput(inputId = slider()$Id, label = h4("Reactive Slider with user-selected min/max:"), min = slider()$min, max = slider()$max, value = slider()$value) | |
, | |
numericInput(inputId = "sliderMin", label = h4(""), value = slider()$min) | |
, | |
numericInput(inputId = "sliderMax", label = h4(""), value = slider()$max) | |
) | |
}) | |
# output value from sliderInput | |
output$sliderValueUI.hide <- renderUI({ | |
if (is.null(input$sliderMin) || is.null(input$sliderMax)) { | |
return() | |
} else { | |
list( | |
br(), tags$hr() | |
, HTML("Slider inputId:"), paste(slider()$Id), br() | |
, HTML("Value read from min box:"), paste(input$sliderMin), br() | |
, HTML("Value read from max box:"), paste(input$sliderMax), br() | |
, tags$hr() | |
) | |
} | |
}) | |
} | |
) |
This file contains hidden or 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
# ui.R | |
library("shiny") | |
shinyUI( | |
basicPage( | |
mainPanel( | |
tags$head(tags$style(type = "text/css" | |
, "#sliderMin {width: 30px; height: 15px; float: left;}" | |
, "#sliderMax {width: 30px; height: 15px; float: right;}" | |
)) | |
, | |
uiOutput("sliderUI") | |
, | |
uiOutput("sliderValueUI") | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment