Last active
August 29, 2015 14:17
-
-
Save timelyportfolio/8752e0ad934299152400 to your computer and use it in GitHub Desktop.
forked from @rich-iannone dogs example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Obtain 'dogs.csv' | |
# Created by Alex Bresler, available at: | |
# https://github.com/abresler/abresler.github.io/blob/master/blog/2015/february/exploring_agility_show/data/dogs.csv | |
dat_url <- "http://asbcllc.com/blog/2015/february/exploring_agility_show/data/dogs.csv" | |
dogs <- read.csv(dat_url, header = TRUE, stringsAsFactors = FALSE) | |
library(shiny) | |
# Install the latest DiagrammeR package from GitHub | |
# devtools::install_github("rich-iannone/DiagrammeR") | |
library(DiagrammeR) | |
library(parcoords) | |
ui = shinyUI( | |
fluidPage( | |
fluidRow( | |
column( width = 6 | |
,parcoordsOutput("parcoords_output", height = "800px") | |
) | |
,column( width = 6 | |
,grVizOutput("grViz_output") | |
) | |
) | |
) | |
) | |
server = function(input,output,session){ | |
output$parcoords_output <- renderParcoords( | |
parcoords( | |
dogs[,c("height_class","breed")] | |
,brushMode="2d" | |
,rownames=F | |
,color=list( | |
colorScale = htmlwidgets::JS("d3.scale.category10()") | |
,colorBy = "height_class" | |
) | |
) | |
) | |
output$grViz_output <- renderGrViz({ | |
# Create a block of Graphviz DOT code | |
# The data frame to work on is 'dogs' | |
# With 'edge_between' specify a directed relationship between the | |
# combined columns 'dog_name' and 'owner', and, 'breed' (you can | |
# make a synthetic node ID by combining columns (i.e., here some | |
# dogs had the same name but they had different owners)) | |
# With 'node_attr', specify the node attributes for the 'breed' | |
# columns and the combined 'dog_name+owner' columns | |
# With 'edge_attr', specify the edge attributes for the first | |
# edge definintion | |
rows <- if(length(input$parcoords_output_brushed_row_names) > 0) { | |
input$parcoords_output_brushed_row_names | |
} else { | |
rownames(dogs) | |
} | |
# don't tell anybody I forced it to work this way | |
assign( | |
"nodes_edges" | |
, graphviz_single_df( | |
df = dogs[rows,], | |
edge_between = c("dog_name+owner -> breed"), | |
node_attr = c("breed: shape = circle, | |
label = , | |
style = filled, | |
fillcolor = seagreen3, | |
height = 0.6", | |
"dog_name+owner: shape = circle, | |
label = , | |
style = filled, | |
fillcolor = turquoise, | |
height = 0.4"), | |
edge_attr = c("1: color = dodgerblue, | |
arrowhead = none"), | |
add_labels = FALSE | |
) | |
, envir = .GlobalEnv | |
) | |
grViz(" | |
digraph dogs { | |
# Graph statements | |
graph [layout = twopi, overlap = false] | |
# Nodes and edges | |
@@1 | |
} | |
[1]: nodes_edges | |
" | |
) | |
}) | |
} | |
shinyApp(ui,server) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment