hrbrmstr / streamgraph

:wavy_dash: htmlwidget for creating streamgraph visualizations in R
http://hrbrmstr.github.io/streamgraph/
Other
148 stars 49 forks source link

Shiny #6

Closed josep2 closed 9 years ago

josep2 commented 9 years ago

Does this library currently support shiny?

hrbrmstr commented 9 years ago

Haven't tried I but it should. I'll whip up an example later tonight to test

On Thursday, February 19, 2015, Jowanza Joseph notifications@github.com wrote:

Does this library currently support shiny?

— Reply to this email directly or view it on GitHub https://github.com/hrbrmstr/streamgraph/issues/6.

hrbrmstr commented 9 years ago

Yep. It seems to do just fine.

library(streamgraph)
library(dplyr)
library(shiny)

ui = shinyUI(fluidPage(
  h3("streamgraph example", style="text-align:center"),
  streamgraphOutput('sg1')
))

server = function(input, output) {

  ggplot2::movies %>%
    select(year, Action, Animation, Comedy, Drama, Documentary, Romance, Short) %>%
    tidyr::gather(genre, value, -year) %>%
    group_by(year, genre) %>%
    tally(wt=value) %>%
    ungroup %>%
    streamgraph("genre", "n", "year") %>%
    sg_axis_x(20) %>%
    sg_fill_brewer("PuOr") %>%
    sg_legend(show=TRUE, label="Genres: ") -> sg

  output$sg1 <- renderStreamgraph(sg)

}

shinyApp(ui = ui, server = server)
ip1200 commented 8 years ago

thx!