Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using brushReset() #28

Open
tbadams45 opened this issue Jul 25, 2016 · 14 comments
Open

Using brushReset() #28

tbadams45 opened this issue Jul 25, 2016 · 14 comments

Comments

@tbadams45
Copy link

Is there a way to call parcoords.brushReset() on a button click? I know it's possible to run custom Javascript using the tasksparameter, but it's my understanding that this can only be used to run Javascript code directly after the parcoords plot has been produced.

I've made a workaround by taking a dependency on a reactive value (v$reset <- runif(1)) that changes everytime the reset button is selected, but it's a little messy.

@timelyportfolio
Copy link
Owner

timelyportfolio commented Jul 25, 2016

In this case, I think we can use the fairly unknown and undocumented HTMLWidgets.find method to accomplish this task. Here is a non-shiny example. On another note, since this was one of my first ever widgets I neglected to add an id argument to parcoords, so finding is difficult. I have resolved with , which will require a reinstall.

library(parcoords)
library(htmltools)

browsable(
  tagList(
    tags$button(id="btn-resetbrush", onclick="reset_brush()", "reset brush"),
    parcoords(mtcars, brushMode="1d", elementId="parcoords1"),
    tags$script(
"
function reset_brush(){
  HTMLWidgets.find('#parcoords1').instance.parcoords.brushReset();
}
"      
    )
  )
)

@tbadams45
Copy link
Author

Excellent! Unfortunately, right now I can't use the master branch because I need to use the dimensions list, so I can't use the elementID, but this is a very smooth answer. Thanks.

@timelyportfolio
Copy link
Owner

Sounds like time to merge the dimensions. I will try to get this done by the end of the week.

@tbadams45
Copy link
Author

Thanks! Much appreciated. Making a great package better. :) Just so you know on my end, the solution (dependency on runif() variable) that I have right now is working, so there's no rush.

@timelyportfolio
Copy link
Owner

timelyportfolio commented Jul 29, 2016

@tbadams45, could I lean on you again to test master? I somehow got out of sync with the resize, so I have had to manually merge the resize and dimensions. There is a change to access the parcoords in JavaScript. I changed the code above to reflect the change. We can do either

document.getElementById('#parcoords1').parcoords.brushReset();
//or note the instance.parcoords

HTMLWidgets.find('#parcoords').instance.parcoords.brushReset();

@tbadams45
Copy link
Author

@timelyportfolio I think so. What would you like me to test specifically? Did you make any changes since #29?

@timelyportfolio
Copy link
Owner

Most changes are internal. If you have a set of examples that you could run quickly to visually inspect, I would really appreciate it. I have run through all my local examples, but I know they are not comprehensive.

@tbadams45
Copy link
Author

@timelyportfolio, I ran a few quick checks in my existing app to see if everything was working as expected. Didn't notice anything unusual. The most complicated example I did is below, and that worked just fine.

parcoords(
      obj_space_disp_data$d, 
      rownames = FALSE,
      brushMode = "1D-axes",
      brushPredicate = "and",
      reorderable = TRUE,
      alpha = 0.6,
      queue = TRUE,
      rate  = 200,
      color = list(
        colorBy = "cost",
        colorScale = htmlwidgets::JS('
          d3.scale.threshold()
          .domain([80000000,90000000,97500000,102500000,107500000,112000000])
          .range(["#feedde","#fdbe85","#fd8d3c","#e6550d","#a63603"])
          ')
        ),
      dimensions = list(
        ID   = list(title = "ID", tickValues = id_ticks),
        cost = list(title = "Cost"),
        dom_rel = list(title = "Dom. Reliability"),
        irr_rel = list(title = "Irr. Reliability"),
        eco_rel = list(title = "Env. Reliability"),
        dom_crel = list(title = "Dom. Crit. Reliability")
      ),
      tasks = htmlwidgets::JS("function f(){this.parcoords.alphaOnBrushed(0.15);}")
    ) 

@timelyportfolio
Copy link
Owner

Great to hear! I will try to keep pushing forward. I really appreciate your help.

@tbadams45
Copy link
Author

Certainly! Thanks for your work.

@timelyportfolio
Copy link
Owner

@tbadams45 if you have any beautiful examples that you produce and would like to contribute, I would love to add them. I have not had the time to make any pretty examples.

@tbadams45
Copy link
Author

Duly noted. I've been spending most of my time related to parcoords incorporating it into a set of linked visualizations to help water planners gain insight into the impacts of different design and operating decisions. However, I'm working as an undergrad in the department and don't have much control about whether or not we release this work to the public... otherwise I'd gladly post everything right now.

@timelyportfolio
Copy link
Owner

timelyportfolio commented Feb 13, 2017

@jtr13, does this #28 (comment) help with your emailed issue? There are lots of options for clearing the brushes. This one adds a button.

@jtr13
Copy link

jtr13 commented Feb 13, 2017

It works! Thanks so much! I was about to ask our 10-year-old where to click to reset (he is good for stuff like that and explaining to me that The Weekend is a person.) If I get good examples from the class I will send them your way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants