Last active
March 12, 2022 21:16
-
-
Save berkorbay/2ff837f8762f9d256573c19b91937216 to your computer and use it in GitHub Desktop.
Changing the min/max labels in Shiny sliders
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
ui <- fluidPage( | |
tags$head( | |
#Using ionRangeSlider's javascript options you can hide/show selector labels and min/max labels | |
HTML(" | |
<script> | |
$(document).ready(function(){ | |
$(\".js-range-slider\").ionRangeSlider({ | |
hide_min_max: false, | |
hide_from_to: true | |
}); | |
}); | |
</script> | |
") | |
), | |
#This CSS hack first hides the text within the span tags of the specified classes | |
#Then it adds desired text and CSS properties. !important parameter is to override | |
#inline css parameters. | |
tags$style(type = "text/css", " | |
.irs-min {visibility:hidden !important;} | |
.irs-max {visibility:hidden !important;} | |
.js-irs-0 .irs .irs-min:after {content:'Hello' !important;} | |
.js-irs-0 .irs .irs-max:after {content:'Shiny' !important;} | |
//Restore css defaults to .irs-min and .irs-max | |
.irs-min:after { | |
visibility: visible !important; | |
display: block; | |
background: rgba(0, 0, 0, 0.1) none repeat scroll 0 0; | |
border-radius: 3px; | |
color: #333; | |
font-size: 10px; | |
line-height: 1.333; | |
padding: 1px 3px; | |
text-shadow: none; | |
top: 0; | |
cursor: default; | |
display: block; | |
left: 0; | |
position: absolute;} | |
.irs-max:after { | |
visibility: visible !important; | |
display: block; | |
background: rgba(0, 0, 0, 0.1) none repeat scroll 0 0; | |
border-radius: 3px; | |
color: #333; | |
font-size: 10px; | |
line-height: 1.333; | |
padding: 1px 3px; | |
text-shadow: none; | |
top: 0; | |
cursor: default; | |
display: block; | |
right: 0; | |
position: absolute;} | |
"), | |
sliderInput(inputId="test", label=NULL, min=1, max=10, value=5, step = 1, width='100%') | |
) | |
server <- function(input, output, session){ | |
} | |
shinyApp(ui = ui, server=server) |
For reasons unknown to me, removing line 27 ('//Restore css defaults to .irs-min and .irs-max') made it also display the minimum label.
When using this code in a Shiny app with multiple sliderInputs, only the first sliderInput is changed accordingly, all the other ones are left are unchanged. How could I apply this to all sliderInputs or to only a few select ones?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, I wonder why this code only paste the text on the maximum side? What I mean is that I can only have "Shiny" on the slider, can I have both? Thx!