Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use sliderInput to to input more than 2 values in Rshiny

Traditionally, a sliderInput function is

sliderInput(inputId, label, min, max, value, step = NULL, round = FALSE, format = NULL, 
locale = NULL, ticks = TRUE, animate = FALSE, width = NULL, sep = ",", 
pre = NULL, post = NULL, timeFormat = NULL, timezone = NULL, dragRange = TRUE)

If I specify

sliderInput("range","range",min=-3,max=3,value=c(-1,1))

it input a range from -1 to 1. However, there is a function takes an argument format as days_included=c(-2,-1,0,1,2). In this case, I cannot make this function work if I set

sliderInput("range","range",min=-3,max=3,value=c(-2,2)) 

since it doesn't really match the required format. So this is my question, anyway to make this function work? I tried "step" argument inside sliderInput but failed.

like image 766
Bratt Swan Avatar asked Aug 26 '16 23:08

Bratt Swan


1 Answers

Your slider returns two values and if you want to have, say, all integers in between, you have to create a sequence using these values and : or with seq functions.

So basically you need input$range[1]:input$range[2]


Minimal example:

library(shiny)
rm(ui) ; rm(server)

ui <- fluidPage(
  br(),
  sliderInput("range","range",min = -3, max = 3, value = c(-2, 2)),
  div(verbatimTextOutput("out1"), style = "width: 300px;")
)

server <- function(input, output) { 

  output$out1 <- renderText({
    # seq.int(from = input$range[1], to = input$range[2])
    input$range[1]:input$range[2]
  })

}
shinyApp(ui, server)
like image 107
Michal Majka Avatar answered Nov 15 '22 09:11

Michal Majka