Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to exclude one value from R Shiny sliderInput?

I have a Shiny sliderInput in my application in which one can choose a year between 2000 and 2022. However, I do not have any data for 2021 which is why I would like to exclude that year and to not have it shown so that the user cannot choose 2021 on the slider because it should not even show up (so the values should be 2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2022).

I’ve searched on here before but did not find something similar. Can anyone help?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As r2evans already points out in the comments, We can use shinyWidgets::sliderTextInput:

library(shiny)
library(shinyWidgets)

shinyApp(ui = fluidPage(
  
  sliderTextInput(
    inputId = "mySliderText",
    label = "Choose Year:",
    choices = c(2000:2020, 2022),
    selected = 2022
  ),
  textOutput("sliderout")
  
  
),

server = function(input, output) {
  output$sliderout <- renderText(input$mySliderText)
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading