Giter Club home page Giter Club logo

d3tree's Introduction

CRAN_Status_Badge Project Status: Active - The project has reached a stable, usable state and is being actively developed. downloads

Reactive shiny filters through collapsible d3js trees

Overview

D3js is a great tool to visualize complex data in a dynamic way. But how can the visualization be part of the natural workflow?

Creating new reactive elements through the integration of Shiny with d3js objects allows us to solve this problem.

Through Shiny we let the server observe the d3 collapsible tree library and its real-time layout.

The data transferred back to Shiny can be mapped to a series of logial expressions to create reactive filters.

This allows for complex data structures, such as heirarchal simulations, complex design of clinical trials and results from polycompartmental structural models to be visually represented and filtered in a reactive manner through an intuitive and simple tool.

d3tree's People

Contributors

thisisnic avatar timelyportfolio avatar yonicd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

d3tree's Issues

app resets R to default library

Hi
Great blog, app and presentation. Hats off for all the work!!

Unfortunately running the app through the "shiny::runGitHub("metrumresearchgroup/SearchTree")" line in R on my comp resets the libPaths to be just the basic directory (i.e. "C:/Program Files/R/R-3.3.0/library") getting rid of my user\home directory where I keep all the packages....
Not sure but probably has something to do with setting .libPaths() to your directory instead of adding it to the list of directories...

input$.nodesData is NULL

when I run the APP, an error is got:

Warning: Error in [[: subscript out of bounds
Stack trace (innermost first):
76: eval
75: eval
74: withVisible
73: evalVis
72: capture.output
71: textConnection
70: renderUI [C:\Users\Administrator\Desktop\SearchTree-master/server.R#109]
69: func
68: output$filterPrint
1: shiny::runApp

so I add "print(input$.nodesData)" in output$filterPrint=renderUI({ ..... }), and the value of input$.nodesData is NULL. Is that the value 'nodesData' didn't pass to shiny?

sessionInfo()

R version 3.2.1 (2015-06-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] rstan_2.12.1 StanHeaders_2.12.0 ggplot2_2.1.0 shinyAce_0.2.1 dplyr_0.4.3
[6] plyr_1.8.3 DT_0.2.7 stringr_1.0.0 shiny_0.13.2 RCurl_1.95-4.7
[11] bitops_1.0-6 reshape2_1.4.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.7 magrittr_1.5 munsell_0.4.3 colorspace_1.2-6 xtable_1.8-2 R6_2.1.3
[7] tools_3.2.1 grid_3.2.1 parallel_3.2.1 gtable_0.2.0 DBI_0.3.1 htmltools_0.3.5
[13] yaml_2.1.13 lazyeval_0.1.10 digest_0.6.10 assertthat_0.1 gridExtra_2.2.1 htmlwidgets_0.7
[19] inline_0.3.14 mime_0.5 stringi_1.1.1 scales_0.4.0 stats4_3.2.1 jsonlite_1.1
[25] httpuv_1.3.3

Allow add other values to node

Hi,
I tried new feature from #7 for use last clicked node. That gave me an idea, that I would like to know, which node it is by their id. I can set new attribute in R list structure and it is propagate to JS nodes, but for active node is returned just value and name.
I suggest return all node properties (activeNode=d;) because we don't know which other attributes we will use next time. What do you think about that?

Vertical layout

Hi,
thank you a lot for this shiny widget! I would like ask you if you have in plan add there option for vertical layout of tree?
The second question is if can widget also return id or name of the last clicked node (collapsed/expanded)

Thanks a lot for response
Frantisek

tree.filter() giving wrong filter expression?

Hi thanks for sharing this great package!

I just started fiddling around with your Titanic example for reactive filters in shiny.

When the root is clicked twice, the filter expression for ID 1 changes from 'Class' to 'Titanic', which doesn't make any sense to me. I'm using d3Tree_0.2.0.

screen


Here is a modified version of the app (using data.table) and utilizing gsub for a workaround:

library(shiny)
library(d3Tree)
library(DT)
library(data.table)
library(datasets)

DT <- unique(setDT(as.data.frame(Titanic)))
variables <- names(DT)
rootName <- "Titanic"

ui <- fluidPage(fluidRow(
  column(
    7,
    column(8, style = "margin-top: 8px;",
      selectizeInput(
      "Hierarchy",
      "Tree Hierarchy",
      choices = variables,
      multiple = TRUE,
      selected = variables,
      options = list(plugins = list('drag_drop', 'remove_button'))
    )),
    column(4, tableOutput("clickView")),
    d3treeOutput(
      outputId = "d3",
      width = '1200px',
      height = '475px'
    ),
    column(12, DT::dataTableOutput("filterStatementsOut"))
  ),
  column(5, style = "margin-top: 10px;", DT::dataTableOutput('filteredTableOut'))
))

server <- function(input, output, session) {
  
  network <- reactiveValues(click = data.frame(name = NA, value = NA, depth = NA, id = NA))
  
  observeEvent(input$d3_update, {
    network$nodes <- unlist(input$d3_update$.nodesData)
    activeNode <- input$d3_update$.activeNode
    if (!is.null(activeNode))
      network$click <- jsonlite::fromJSON(activeNode)
  })
  
  output$clickView <- renderTable({
    req({as.data.table(network$click)})
  }, caption = 'Last Clicked Node', caption.placement = 'top')
  
  filteredTable <- eventReactive(network$nodes, {
    if (is.null(network$nodes)) {
      DT
    } else{
      filterStatements <- tree.filter(network$nodes, DT)
      filterStatements$FILTER <- gsub(pattern = rootName, replacement = variables[1], x = filterStatements$FILTER)
      network$filterStatements <- filterStatements
      DT[eval(parse(text = paste0(network$filterStatements$FILTER, collapse = " | ")))]
    }
  })
  
  output$d3 <- renderD3tree({
    if (is.null(input$Hierarchy)) {
      selectedCols <- variables
    } else{
      selectedCols <- input$Hierarchy
    }
    
    d3tree(
      data = list(
        root = df2tree(struct = DT[, ..selectedCols][, dummy.col := ''], rootname = rootName),
        layout = 'collapse'
      ),
      activeReturn = c('name', 'value', 'depth', 'id'),
      height = 18
    )
  })
  
  output$filterStatementsOut <- renderDataTable({
    req({network$filterStatements})
  }, caption = 'Generated filter statements', server = FALSE)
  
  output$filteredTableOut <- DT::renderDataTable({
    filteredTable()
  }, caption = 'Filtered table', server = FALSE, options = list(pageLength = 20))
  
}

shinyApp(ui = ui, server = server)

use data.tree or GeneralTree for better tree manipulation in R

As I started to write the convert the d3 tree back to R function, I realized that even when converted, it will be difficult to manipulate in R. I thought data.tree or GeneralTree might be more useful, but it mostly depends on how much tree manipulation you will need to accomplish and if you are ok with additional dependencies.

Either way, I will try to get a d3 json to tibble function finished by the end of the day.

"_update" added at the end of Shiny input names

First of all, thank you for your work on the amazing packages.

I’m new to shiny and I’m trying to develop an app using the d3tree package. I notice that to call some input id’s I have to add “_update” at the end (from some of the examples available in GitHub). Would you mind pointing me towards where I can learn when I should add _update or other suffixes to input ids in shiny? I am at a loss as to when this should be the case and can’t find any guidance online.

Thank you!

Natalie

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.