med-material / r-shiny-js-data-capture

Data Capture System in Javascript, integrated into R Shiny
MIT License
1 stars 1 forks source link

Integrate JS Capture into R Shiny #3

Closed bastianilso closed 1 year ago

bastianilso commented 1 year ago

Now that we have a prototype implementation of a JS event capture system, we should investigate how to integrate it into a basic R shiny application, for example the R shiny application found in the brush_whack folder. There are a few things to consider:

bilal-62210 commented 1 year ago

@bastianilso I am still working on this, currently i can capture all events for all Elements except for the plotlyoutput. Can you help me to find the solution for this element please ?

bastianilso commented 1 year ago

@bilal-62210 what did you try?

bilal-62210 commented 1 year ago

@bastianilso i tried to change 'plotlyoutput' to 'plotoutput', in this case i managed to capture the id but the chart is not showing on the app, so this it didn't work. I tried also to give to the plotlyoutput an 'outputid' instead of the basic 'id' and this didn't work too. I tried also to include the plotlyoutput in a "

to call the div id when the mouse hovers over the plotlyoutput and it didn't work. So i think the issue is that the 'plotlyouput' is reactive because for a basic 'plotouput' it works.

bastianilso commented 1 year ago

@bilal-62210 did you try to use a jQuery style of binding your log function instead?

See my suggestion here: https://github.com/med-material/r-shiny-js-data-capture/issues/1#issuecomment-1257627352

Think about this: How do you know when the HTML DOM changes? If you are subscribing all elements at the beginning to your logging, but then something in the HTML changes, how do you ensure the new elements are also subscribed to your logging? Maybe this is the problem?

take a look at: https://stackoverflow.com/questions/15657686/jquery-event-detect-changes-to-the-html-text-of-a-div

bilal-62210 commented 1 year ago

Hi @bastianilso This is what i did exactly for the plotlyoutput id :

all these tests did not work. As i said yesterday, if we can't find the solution to get the plotlyoutput id we can put the value to null for the "element" field on the csv file when there is a mouse event on a plotlyoutput(but we still have the screen-x and y values).

bastianilso commented 1 year ago

Hi @bilal-62210 thanks for the report and for trying these.

Here are my suggestions to you to try next to solve this:

  1. Plotly uses SVG for its output in many cases, and in other cases WebGL. I manipulated your HTML file to include a some basic SVG elements. Please try if your JS capture system can detect hovering over the SVG element as a whole and the individual SVG elements (ellipses). web_page2-with-svg.zip

  2. Try and see whether you can integrate this Codepen into your HTML file and use the JS capture system on the plot (this uses Plotly.js outside R Shiny, this way we can test it in isolation): https://codepen.io/mmakrzem/pen/mdOpWLd

  3. Try to see if you can use your JS data capture system on the visualization produced by Aldryck.

bastianilso commented 1 year ago

@bilal-62210 I posted a question in the plotly community forum. We have one reply already, please have a look.

https://community.plotly.com/t/detecting-mouse-events-within-plotly-plots-from-external-js-script/68676

bastianilso commented 1 year ago

Other suggestions to try out:

  1. Try loading the data capture directly from the browser inspector, by manipulating the HTML code and see if your function can be called this way.
bastianilso commented 1 year ago

Now that we have elementFromPoint, we don't have to rely on this other issue solely, so I'll resolve this.