I have an issue with sliderInput
. In my app, when a user loads data (actionBTTN
) the years of my sliderInput
get updated (with updateSliderInput
) according to that data. But I have noticed that for data containing few years (4-5) the sliderInput
would show repeated years. I also noticed, that it seems to only happens when my screen size is bigger.
Here is how it looks with a small sized window: no duplicated year values, how I would like it to be in the app And here is how it looks with a larger window: duplicated year values
Here is an example of my app:
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
# initial input with no years selected, it will update once data is loaded
sliderInput(
inputId = "years",
label = "Choose a time range:",
min = 0, max = 1,
value = c(0,1),
#dragRange = TRUE,
step = 1,
sep = ''
),
actionBttn(
inputId = "load_data",
label = "Get data!",
color = "primary",
style = "fill",
icon = icon("arrow-alt-circle-down"),
size = "xs",
block = TRUE
)
),
mainPanel()
)
)
server = function(input, output, session) {
observeEvent(input$load_data, {
mydata <- data.frame(numbers = c(1:5), year = c(2010:2014))
minim = min(mydata$year)
maxim = max(mydata$year)
updateSliderInput(session, inputId = "years",
min = minim, max = maxim,
value = c(minim, maxim),
# calculate step dynamically (@Isa's idea)
step = seq(minim, maxim, length.out = length(mydata$year))[2] - seq(minim, maxim, length.out = length(mydata$year))[1])
})
}
shinyApp(ui, server)
I have already tried changing the step
and sep
arguments, also seting mydata$year
as integer. Has anybody encountered the same issue?
All help is welcome.
Thanks :)