block by timelyportfolio acab696ab8b31580e37395114dd11a78

parcoords brush clear

Full Screen
#  using experiments-brush branch of parcoords
# devtools::install_github("timelyportfolio/parcoords@experiments-brush")
library(parcoords)
library(htmltools)

# get a parcoords that we can hack later
pc <- parcoords(
  mtcars,
  brushMode = "1d",
  height = 350
)

browsable(
  tagList(
    tags$button(id="btn-clear", "clear"),
    tags$select(
      name = "cyl",
      id = "select-cyl",
      multiple = "true",
      tags$option(4),
      tags$option(6),
      tags$option(8)
    ),
    pc,
    tags$script(HTML(
"
d3.select('#select-cyl').on('change', function() {
  var pc = HTMLWidgets.find('.parcoords').instance.parcoords
  var selected = []
  d3.select(this).selectAll('option:checked').each(function(d){
    selected.push(+this.value)
  })

  var filters = pc.outsideFilters() || {}

  if(selected.length > 0) {
    filters.cyl = selected
    pc.outsideFilters(filters)
  } else {
    delete filters.cyl
    pc.outsideFilters(filters)
  }

  // now update
  pc.brushUpdated(pc.selected())
})

d3.select('#btn-clear').on('click', function() {
  var pc = HTMLWidgets.find('.parcoords').instance.parcoords

  pc.brushReset()

  pc.outsideFilters(null)

  d3.selectAll('option').each(function(d) {
    d3.select(this).property('selected', false)
  })
})
"
    ))
  )
)