I'm trying to make a slider input that has years between 2005 and 2040. It seems pretty simple, right? Normally it works fine, but every once in a while I will pull the slider too far to the left and it gives me NaN, which tends to crash things. I've tried to set up the rest of my code so that it doesn't have a problem, but it's still bugging me. I've scoured the Internet for explanations, but so far nothing. Here's my ui.R:
library(shiny)
shinyUI(fluidPage(
titlePanel("Test"),
sidebarLayout(
sidebarPanel(
selectInput("over", "Indicator", c("Indicator 1", "Indicator 2"), selected="Trade"),
selectInput("type", "Type", c("Discrete", "Continuous")),
# Nothing particularly unusual here...
sliderInput("year", "Year", min=2005, max=2040, value=2005, animate=animationOptions(interval=1500), sep=""),
checkboxInput("table", "Show Table")
, width=3),
mainPanel(
uiOutput("plot"),
uiOutput("showtable")
, width=9)
)
))
I think the problem might lie with your sep
parameter. Is that supposed to be step
? If so, it needs to be either a number or NULL
. I changed that line to the following:
sliderInput("year", "Year", min=2005, max=2040, value=2005, animate=animationOptions(interval=1500), step=1),
It worked fine. At least, I was able to drag as far left as I wanted without any issue. On the other hand, I don't have your server.R
file, so if the problem is there, or with an interaction between the files, I wouldn't see it.
The problem is with your version of Shiny. I discovered this because the sep
parameter was an "unused argument" when I tried to run the app. I originally thought this was a typo, but your certainty (in your recent comment) caused me to check with the documentation for sliderInput
. You are totally right, sep
is a valid parameter. I figured this meant my version of the shiny
package was out of date, so I updated it. After I updated it, not only did sep
parameter get accepted, but I was able to replicate your issue. I found that if I attempted to drag the slider off of the browser window, its value would change to NaN. Also, the slider looks much prettier. I am guessing this has to do with a change in the code for the sliderInput
function. I will take a look at that and update again if I find the change.
I found the issue. In the latest version of Shiny, they decided to use a range slider written in jQuery called ion.rangeSlider
. Specifically, they used version 2.0.2. Unfortunately, that version had an issue with returning NaN when the left slider was pulled off of the browser window (sound familiar?). That has been fixed in the most recent version of ion.rangeSlider
(2.0.6). I hope that the next release of the shiny
package incorporates the most recent version of ion.rangeSlider
.
I know this doesn't actually solve your problem. However, the following will:
Then just detach and reload the shiny
package, and you should be all set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With