Is there a way to interactively drag points in a scatterplot created bu shiny ?

1,358 views
Skip to first unread message

Grégoire Vincke

unread,
Oct 21, 2013, 10:43:05 AM10/21/13
to shiny-...@googlegroups.com
Hi everybody,

Do you know if it is possible to create with shiny an app quite close to this one, build in Flash several years ago, and allowing to drag points in a scatterplot and view consequencies to all parameters of a linear regression ?

http://sites.uclouvain.be/selt/ressources/104013 (in french)

We want all the points to be dragables with the mouse. Computation of all parameters must not be synchronus, but synchronicity is a plus.

I do not search someone to build it, but just to know if you think it is possible, and how (libraries, javascript tips, etc).

Thanks a lot for your advises.

Grégoire


John Harrison

unread,
Oct 21, 2013, 3:21:17 PM10/21/13
to shiny-...@googlegroups.com
Hi Gregoire,

Thats a really nice app. I think you could do something similar in shiny. You could start with the jqplot javascript library.
I have thrown together a quick example based on one of the jqplot examples at:

http://spark.rstudio.com/johnharrison/draggable/

John

Stéphane Laurent

unread,
Oct 21, 2013, 4:56:35 PM10/21/13
to shiny-...@googlegroups.com
Hello John, 

Your app appears "frozen" for me. I'm using Chrome and Windows XP.

John Harrison

unread,
Oct 21, 2013, 6:22:47 PM10/21/13
to shiny-...@googlegroups.com
Hi Stephane,

It should be working now. I was adjusting the example to depend on the input and also to more closely match the OP's app in spirit.

John

John Harrison

unread,
Oct 21, 2013, 6:34:22 PM10/21/13
to shiny-...@googlegroups.com
The code to run this example can be found at: https://gist.github.com/johndharrison/7092047

You would need to have the jqPlot library found at http://www.jqplot.com/deploy/download/jquery.jqplot.1.0.4r1121.zip for example. I placed the contents of this file
in www and linked to them in the ui.R

Vincke Grégoire

unread,
Oct 22, 2013, 3:40:37 AM10/22/13
to shiny-...@googlegroups.com
Hi John,

Brilliant !!

Thanks a lot for this illustrated example which fits exactly what i
expected. This will be a very good base to extend this app to reach our
didactic goal.

Now i know that i can start to investigate shiny more closely to build
this kind of apps.

Future goals of this app :
* change the regression model from linear to exponential, power,
logarithm, etc
* draw interval of confidence of regression
* last but not least : add points by clicking directly on the graph

I will let a message on this list when it's done.

Have a nice day !

Gr�goire





Le 21/10/2013 21:21, John Harrison a �crit :
> Hi Gregoire,
>
> Thats a really nice app. I think you could do something similar in
> shiny. You could start with the jqplot javascript library.
> I have thrown together a quick example based on one of the jqplot
> examples at:
>
> http://spark.rstudio.com/johnharrison/draggable/
>
> John
> On Monday, October 21, 2013 9:43:05 PM UTC+7, Gr�goire Vincke wrote:
>
> Hi everybody,
>
> Do you know if it is possible to create with shiny an app quite
> close to this one, build in Flash several years ago, and allowing to
> drag points in a scatterplot and view consequencies to all
> parameters of a linear regression ?
>
> http://sites.uclouvain.be/selt/ressources/104013
> <http://sites.uclouvain.be/selt/ressources/104013> (in french)
>
> We want all the points to be dragables with the mouse. Computation
> of all parameters must not be synchronus, but synchronicity is a plus.
>
> I do not search someone to build it, but just to know if you think
> it is possible, and how (libraries, javascript tips, etc).
>
> Thanks a lot for your advises.
>
> Gr�goire
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Shiny - Web Framework for R" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/shiny-discuss/d9lKfsVXVJM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> shiny-discus...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Stéphane Laurent

unread,
Oct 22, 2013, 3:51:45 AM10/22/13
to shiny-...@googlegroups.com
Yes it works now. Very nice. 

But if we move a point in the javascript graphic, can we get its new coordinates in R ?

Actually I'd like to be able to remove a point from the sample, in order to see its influence on the fitted regression model.

Stéphane Laurent

unread,
Oct 22, 2013, 3:55:36 AM10/22/13
to shiny-...@googlegroups.com
I'm not sure it fits your expectation because the regression line is calculated by the javascript code, not by R, isnt'it ?

Vincke Grégoire

unread,
Oct 22, 2013, 4:11:56 AM10/22/13
to shiny-...@googlegroups.com
Hi St�phane, John

As soon as i just start to analyse the code, i would say yes.

The all graph seems to be genereted by javascript instead of R, which in
fact reduce the future possibilities of interaction with R.

I will pay attention to that and will search a way to have the benefit
of the both frameworks.

St�phane, thanks for notice.

John, do you know if it's possible to maybe use this javascript as a
layer over an R genereted program, and if it's possible to store the
coordinates of each point to feed R with them ?

Thanks.

Gr�goire







Le 22/10/2013 09:55, St�phane Laurent a �crit :
> I'm not sure it fits your expectation because the regression line is
> calculated by the javascript code, not by R, isnt'it ?
>
>
> Le mardi 22 octobre 2013 09:40:37 UTC+2, Gr�goire Vincke a �crit :
>
> Hi John,
>
> Brilliant !!
>
> Thanks a lot for this illustrated example which fits exactly what i
> expected.
>

Kirill Savin

unread,
Oct 22, 2013, 4:23:03 AM10/22/13
to shiny-...@googlegroups.com
Definitely doable. You may want to check this tutorial and this topic.

On Tuesday, October 22, 2013 4:11:56 AM UTC-4, Grégoire Vincke wrote:
Hi St�phane, John

As soon as i just start to analyse the code, i would say yes.

The all graph seems to be genereted by javascript instead of R, which in
fact reduce the future possibilities of interaction with R.

I will pay attention to that and will search a way to have the benefit
of the both frameworks.

St�phane, thanks for notice.

John, do you know if it's possible to maybe use this javascript as a
layer over an R genereted program, and if it's possible to store the
coordinates of each point to feed R with them ?

Thanks.

Gr�goire







Le 22/10/2013 09:55, St�phane Laurent a �crit :
> I'm not sure it fits your expectation because the regression line is
> calculated by the javascript code, not by R, isnt'it ?
>
>
> Le mardi 22 octobre 2013 09:40:37 UTC+2, Gr�goire Vincke a �crit :

John Harrison

unread,
Oct 22, 2013, 11:03:44 AM10/22/13
to shiny-...@googlegroups.com
The key  thing here is that you can drag the points. Once the points are dragged a javascript event is fired and you can recover the new coordinates. You can use these new coordinates at any time to
draw whatever graph you would like. I just used the build in javascript trendline as a prove of concept. It would be pretty straightforward to extend the example. If I get some time I will extend the example so R is providing the trendline and also the varioys fitted values etc.

John

Vivian Chen

unread,
Aug 26, 2015, 1:21:37 PM8/26/15
to Shiny - Web Framework for R

Hi John,

I searched and found your post on doing interactive plots with shiny. I've downloaded your script but somehow it doesn't run for me. I can only get the sidepanel on the UI but not the main. Would you share some lights here?

Thanks,
Viv
Reply all
Reply to author
Forward
0 new messages