Giter VIP home page Giter VIP logo

Comments (7)

timelyportfolio avatar timelyportfolio commented on May 19, 2024

in 1f37d1d, I start to add the Shiny integration, by returning the celltext/likely name of the clicked cell. Here is a basic example.

library(shiny)
library(treemap)
library(d3treeR)

data(business)
tm <- treemap(business,
              index=c("NACE1", "NACE2","NACE3"),
              vSize="employees",
              fontsize.labels=12,
              lowerbound.cex.labels=1, draw = F)

ui <- list(
  d3tree2Output( 'tree' )
  ,textOutput( "clickedinfo", container = p )
)

server <- function( input, output, session ){
  output$tree <- renderD3tree2({
    d3tree2( tm )
  })

  # from https://github.com/rstudio/leaflet/blob/master/inst/examples/shiny.R
  v <- reactiveValues(msg = "")

  observeEvent(input$tree_click, {
    v$msg <- paste("Clicked ", input$tree_click$name)
  })

  output$clickedinfo <- renderText(v$msg)
}

shinyApp( ui, server )

I'll start experimenting with the second part of the request which is a generalizable click handler that could trigger actions on the JavaScript side.

from d3treer.

timelyportfolio avatar timelyportfolio commented on May 19, 2024

@ellisp ad0d8b0 should provide a first implementation of clickAction for d3tree2. I opted for what I considered the easier but much more limited form of the implementation. If I can broaden my assumption that someone providing clickAction understands JavaScript call/this, then I could use the more powerful form where I call the clickAction with d which is all the node info, g which is the SVG element, and el which is the htmlwidget element. In this case function(){return this} would give us an object {d:...,g:...,el:...}

from d3treer.

ellisp avatar ellisp commented on May 19, 2024

brilliant, I'll have a look some time this week

from d3treer.

ellisp avatar ellisp commented on May 19, 2024

This is great and gets me most of the way where I was hoping, except that when you get to the end of the hierarchy and click on one of the twigs of the tree it doesn't register. It doesn't need to for treemap-drawing purposes as it's already got the most granular graphic up there, but it would be good to have that final twig known to the app when it's clicked on.

from d3treer.

timelyportfolio avatar timelyportfolio commented on May 19, 2024

Oh I missed that. I should be able to push that out tonight. Thanks.

from d3treer.

timelyportfolio avatar timelyportfolio commented on May 19, 2024

I think I got it right in 3f30077. The examples provided above now communicate click/selection on the top grandparent level (title bar), parent level, and at the cell level including the leaves. If possible, please test on your end.

It is still not the most elegant solution, but I'll probably leave it as is for now.

Thanks again.

from d3treer.

ellisp avatar ellisp commented on May 19, 2024

Tested at my end and it does the job, thanks.

from d3treer.

Related Issues (20)

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.