timelyportfolio / timelineR

R htmlwidget for interactive d3.js timelines using d3.layout.timeline
http://www.buildingwidgets.com/blog/2015/12/30/week-52-d3kittimeline
Other
26 stars 5 forks source link

allow non-date data with d3kit_timeline #2

Open timelyportfolio opened 8 years ago

timelyportfolio commented 8 years ago

@pssguy brings up a great use case to visualize soccer goals, but currently d3kit_timeline does not allow non-date data.

timelyportfolio commented 8 years ago

reference https://github.com/kristw/d3kit-timeline/issues/3

timelyportfolio commented 8 years ago

@pssguy, I committed some experimental code to make this work. Try with your data. As another example,

library(timelineR)

# old "nonworking"
d3kit_timeline(
  data.frame(time = 1:3),
  textFn = ~time,
  margin = list(left=100,right=20,bottom=20,top=20)
)

# new working
d3kit_timeline(
  data.frame(time = 1:3),
  textFn = ~time,
  margin = list(left=100,right=20,bottom=20,top=20),
  scale = htmlwidgets::JS("d3.scale.linear()")
)

# new working improved with custom domain
d3kit_timeline(
  data.frame(time = 1:3),
  textFn = ~time,
  margin = list(left=100,right=20,bottom=20,top=20),
  scale = htmlwidgets::JS("d3.scale.linear()"),
  domain = c(0,5)
)

# some additional customization
add_axis(
  d3kit_timeline(
    data.frame(time = 1:3),
    textFn = ~time,
    margin = list(left=100,right=20,bottom=20,top=20),
    scale = htmlwidgets::JS("d3.scale.linear()"),
    domain = c(0,5),
    height =100
  ),
  ticks=3
)
pssguy commented 8 years ago

Thanks . Looks good and I can translate to my data smoothly

However, I'm having problems utilizing in shiny. The browser is launched but nothing appears There do seem to be some some errors according top console

e.g Error: Invalid value for attribute x="NaN"

Can you replicate Any idea what I am doing incorrectly?

library(shiny)
library(timelineR)

app <- shinyApp(
    ui = fluidPage(
     timelineOutput("timeline")
  ),
  server = function(input, output) {
    output$timeline <- renderTimeline({

      df <- data.frame(time = 1:3)
      d3kit_timeline(
        df,
        textFn = ~time,
        margin = list(left=100,right=20,bottom=20,top=20),
        scale = htmlwidgets::JS("d3.scale.linear()"),
        domain = c(0,5) 
      )

      })
  }
)
runApp(app)
timelyportfolio commented 8 years ago

@pssguy just getting back on the computer. I stripped out the Shiny piece as I was experimenting, and I forgot to put it back. I'll add it tonight or tomorrow morning. Sorry. Also, the source d3kit-timeline officially got this new functionality, so I'll merge it in also.

timelyportfolio commented 8 years ago

I added back the Shiny, and upgraded to 0.2.0 of d3kit-timeline. Thanks again. Also thought you would like the example added at http://kristw.github.io/d3kit-timeline/.

library(shiny)
library(timelineR)

app <- shinyApp(
  ui = fluidPage(
    d3kit_timelineOutput("timeline")
  ),
  server = function(input, output) {
    output$timeline <- renderd3kit_timeline({

      df <- data.frame(time = 1:3)
      d3kit_timeline(
        df,
        textFn = ~time,
        margin = list(left=100,right=20,bottom=20,top=20),
        scale = htmlwidgets::JS("d3.scale.linear()"),
        domain = c(0,5) 
      )

    })
  }
)
runApp(app)
pssguy commented 8 years ago

Thanks. Works fine. I'll have a working interactive up this evening