ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 29 May 2012 22:41:52 +0200Are there options for interactive/dynamic content?https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/I'm starting to switch over to sage from mathematica, and so far the biggest thing I'm missing is the ability to make interactive applets. I managed to get [mplh5canvas](http://code.google.com/p/mplh5canvas/) up and running. While it's a nice start, It's far from the sort of thing I can do with mathematica.
In mathematica, one can make an interactive sin graph with something like (I forget if the dynamic tag goes with the a or the plot[]):
Slider[Dynamic[a],{0,5}]
Plot[Dynamic[a]*sin[x],{x,-10,10}]
And of course it's even easier with Manipulate[].
How far is Sage from this sort of functionality? I think this sort of thing is immensely helpful to students who just want to explore a function.
If I learn how to effectively use the HTML 5 canvas and javascript, are dynamic plots within reach?
EDIT: Thanks a lot! Interact seems to be what I was looking for.Tue, 29 May 2012 17:59:39 +0200https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/Answer by Eviatar Bach for <p>I'm starting to switch over to sage from mathematica, and so far the biggest thing I'm missing is the ability to make interactive applets. I managed to get <a href="http://code.google.com/p/mplh5canvas/">mplh5canvas</a> up and running. While it's a nice start, It's far from the sort of thing I can do with mathematica.</p>
<p>In mathematica, one can make an interactive sin graph with something like (I forget if the dynamic tag goes with the a or the plot[]):</p>
<pre><code>Slider[Dynamic[a],{0,5}]
Plot[Dynamic[a]*sin[x],{x,-10,10}]
</code></pre>
<p>And of course it's even easier with Manipulate[].</p>
<p>How far is Sage from this sort of functionality? I think this sort of thing is immensely helpful to students who just want to explore a function.</p>
<p>If I learn how to effectively use the HTML 5 canvas and javascript, are dynamic plots within reach?</p>
<p>EDIT: Thanks a lot! Interact seems to be what I was looking for.</p>
https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/?answer=12171#post-id-12171Yes, there is a way to do this, with `interact`.
For your example, the equivalent in Sage would be (this goes in a notebook cell):
@interact
def interact_sin(a=slider(0, 5)):
plot(a * sin(x), -10, 10).show()Tue, 29 May 2012 19:03:51 +0200https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/?answer=12171#post-id-12171Comment by Shashank for <p>Yes, there is a way to do this, with <code>interact</code>.</p>
<p>For your example, the equivalent in Sage would be (this goes in a notebook cell):</p>
<pre><code>@interact
def interact_sin(a=slider(0, 5)):
plot(a * sin(x), -10, 10).show()
</code></pre>
https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/?comment=19725#post-id-19725Yes I understand. My comment was for the OP.Tue, 29 May 2012 22:41:52 +0200https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/?comment=19725#post-id-19725Comment by Eviatar Bach for <p>Yes, there is a way to do this, with <code>interact</code>.</p>
<p>For your example, the equivalent in Sage would be (this goes in a notebook cell):</p>
<pre><code>@interact
def interact_sin(a=slider(0, 5)):
plot(a * sin(x), -10, 10).show()
</code></pre>
https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/?comment=19726#post-id-19726Yeah, but I wanted to make it the same as the poster's example.Tue, 29 May 2012 19:14:28 +0200https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/?comment=19726#post-id-19726Comment by Shashank for <p>Yes, there is a way to do this, with <code>interact</code>.</p>
<p>For your example, the equivalent in Sage would be (this goes in a notebook cell):</p>
<pre><code>@interact
def interact_sin(a=slider(0, 5)):
plot(a * sin(x), -10, 10).show()
</code></pre>
https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/?comment=19727#post-id-19727plot(a * sin(x), -10, 10,ymin=-5,ymax=5).show() looks better.Tue, 29 May 2012 19:07:14 +0200https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/?comment=19727#post-id-19727Answer by Shashank for <p>I'm starting to switch over to sage from mathematica, and so far the biggest thing I'm missing is the ability to make interactive applets. I managed to get <a href="http://code.google.com/p/mplh5canvas/">mplh5canvas</a> up and running. While it's a nice start, It's far from the sort of thing I can do with mathematica.</p>
<p>In mathematica, one can make an interactive sin graph with something like (I forget if the dynamic tag goes with the a or the plot[]):</p>
<pre><code>Slider[Dynamic[a],{0,5}]
Plot[Dynamic[a]*sin[x],{x,-10,10}]
</code></pre>
<p>And of course it's even easier with Manipulate[].</p>
<p>How far is Sage from this sort of functionality? I think this sort of thing is immensely helpful to students who just want to explore a function.</p>
<p>If I learn how to effectively use the HTML 5 canvas and javascript, are dynamic plots within reach?</p>
<p>EDIT: Thanks a lot! Interact seems to be what I was looking for.</p>
https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/?answer=13631#post-id-13631There are a few examples on the sagemath.org website. Have a look at the following links
http://wiki.sagemath.org/interact/calculus
http://wiki.sagemath.org/interact/algebra
Tue, 29 May 2012 18:27:26 +0200https://ask.sagemath.org/question/9014/are-there-options-for-interactivedynamic-content/?answer=13631#post-id-13631