Ask Your Question
1

@interact produces html output instead of interactive diagram

asked 2016-12-23 14:55:44 +0100

thwee0 gravatar image

I tried to make an interactive diagram by placing @interact before the myplot function:

def myplot(f=(c_repulsion / (epsilon + abs(d))^2) * ((d) / abs(d))):
    show(plot(f, (d,-10, 10)))

much like it's described in the tutorials.

But the output looks literally like this:

<html><!--notruncate-->
        <div padding=6 id="div-interact-0">
          <table width=800px height=20px bgcolor="#c5c5c5" cellpadding=15>
            <tr>
              <td bgcolor="#f9f9f9" valign=top align=left>
            <table>
              <tr><td colspan=3><table><tr><td align=right><font color="black">f&nbsp;</font></td><td><input type="text" value="100*d/((abs(d) +
0.00100000000000000)^2*abs(d))" size=80 onchange="interact(0, {variable: 'f', adapt_number: 1, value: encode64(this.value)}, 1)"></input></td> </tr></table></td></tr>
              <tr><td></td><td style='width: 100%;'>
        <div id="cell-interact-0"><?__SAGE__START>
          <table border=0 bgcolor="white" width=100%>
            <tr>
              <td bgcolor="white" align=left valign=top>
                <pre><?__SAGE__TEXT></pre>
              </td>
            </tr>
            <tr>
              <td align=left valign=top><?__SAGE__HTML></td>
            </tr>
          </table><?__SAGE__END>
        </div></td><td></td></tr>
              <tr><td colspan=3></td></tr>
            </table></td>
            </tr>
          </table>
        </div></html>
edit retag flag offensive close merge delete

Comments

What operating system and what version of Sage are you running?

Are you using (a) the Sage REPL, (b) the Sage Notebook, (c) the Jupyter Notebook?

slelievre gravatar imageslelievre ( 2016-12-23 18:53:06 +0100 )edit

I downloaded the Sagemath 7.4 appliance from sagemath.org. I think it runs on CentOS, though I don't know the version. For viewing the notebook, I use Google Chrome Version 55.0.2883.87 m (64-bit) on Windows 10. The Notebook Viewer reads Jupyter on top. I'm pretty new to Sage.

thwee0 gravatar imagethwee0 ( 2016-12-26 12:12:57 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-12-23 21:34:57 +0100

The def line following @interact needs to contain the variables being changed, not the function of the variables. Here's a modified version of your code that produces the expected output:

@interact
def myplot(c_repulsion=(0.1,1), epsilon=(.1,1)):
    var('d')
    f = (c_repulsion / (epsilon + abs(d))^2) * (d / abs(d))
    show(plot(f, (d,-10, 10), ymin=-2, ymax=2, detect_poles=true))

I've added ymin and ymax to prevent the area around the origin from controlling the appearance of the plot too much, and detect_poles to remove the blue line on the y-axis.

Here's a live example of the code.

edit flag offensive delete link more

Comments

I tried running your code in the configuration I mentioned in the comment to the question, but still html is being produced instead of a rendered widget.

thwee0 gravatar imagethwee0 ( 2016-12-26 12:14:28 +0100 )edit

Sage interacts are not yet fully compatible with Jupyter notebooks (https://trac.sagemath.org/ticket/21267). I've just confirmed that the interact doesn't render properly in a Jupyter notebook for OS X Sierrra either.

This code will work in a legacy Sage notebook, which you can start by typing notebook() at the Sage command line. If you want to use the Jupyter notebook, then it looks like you'll need to learn about ipywidgets until Sage interacts are updated.

paulmasson gravatar imagepaulmasson ( 2016-12-26 20:29:49 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2016-12-23 14:55:44 +0100

Seen: 363 times

Last updated: Dec 23 '16