4

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)
  )
))
IonDen
  • 773
  • 5
  • 15
Caroline
  • 450
  • 1
  • 5
  • 15
  • A question for self-education--why do you need `animate=animationOptions(interval=1500)`? – Marat Talipov Mar 04 '15 at 23:41
  • 1
    I was having issues with the data loading in time when it was the default (interval=1000). I've done some optimizing since then, though, and I could probably take it out. However, the problem started before I added that. – Caroline Mar 05 '15 at 17:21

1 Answers1

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.

Update:

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.

Update2

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:

  1. Figure out where your R packages are installed
  2. Go to the subfolder shiny\www\shared\ionrangeslider\css
  3. Copy the file ion.rangeSlider.skinShiny.css to somewhere else
  4. delete the contents of shiny\www\shared\ionrangeslider
  5. Download the .zip of ion.rangeSlider here
  6. Copy the contents of ion.rangeSlider-master into the ionrangeslider folder mentioned in step 2
  7. Move ion.rangeSlider.skinShiny.css back into shiny\www\shared\ionrangeslider\css

Then just detach and reload the shiny package, and you should be all set.

Community
  • 1
  • 1
Paul de Barros
  • 1,170
  • 8
  • 22
  • 1
    The sep="" was intended to take out the comma between the thousands and hundreds place, since it isn't customary to do that with years. It works just fine for that purpose. I added step=1, but that didn't fix the problem. Note that the slider shows NaN--it's not just that R returns an error--the actual slider shows NaN. – Caroline Mar 05 '15 at 17:25
  • I updated my answer to reflect that I was able to reproduce your issue, but not solve it yet. – Paul de Barros Mar 05 '15 at 20:00
  • 1
    Aha! Ok, then I'm not crazy. The only problem is that I'm not running this locally--I'm using shinyapps.io to host it. Still, glad to at least know that the bug is on their side and that hopefully, it will eventually be fixed. – Caroline Mar 09 '15 at 13:25
  • You could also include code to override the slider function with the earlier version, so you get the slightly less pretty slider that does not produce NaNs. And if you think that my answer is sufficient, would you [accept](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work?lq=1) it? That involves clicking the check mark on the left under the vote arrows. – Paul de Barros Mar 09 '15 at 16:40
  • Thanks for the investigation. I updated to the new version of ionRangeSlider in the development version of Shiny, so the problem should be fixed now. – wch Mar 27 '15 at 20:32