Hi, 

The @interact command does not seem to work correctly in Sage 7.3 (See 
Example 1)

I also tried the following import which I found online:

from ipywidgets import interact, interactive, fixedimport ipywidgets as widgets


The result was better but didn't contain a slider! See the attached figure.


Note it still works with the old style notebooks in Sage 7.3!


------------------------------------------------------------------------------------------------------------------
Example 1:


def plotNthRoots(n):
    # Create a unit circle
    c = circle((0,0), radius=1, rgbcolor=(1,0,0))
    # Combine the circle with points on the circle representing the roots 
of unity
    theta = 2.0*pi/float(n)
    p = c + point([(cos(t), sin(t)) for t in srange(0, 2.0*pi, 
theta)],frame=True,size=60)
    # Add in vectors from the origin to the roots of unity.
    p = p + sum([arrow2d( (0,0), (cos(t),sin(t)) ) for t in srange(0, 
2.0*pi, theta)])
    show(p)
    print("The Principle %d-Root: (%5.3f)+(%5.3f)I"%(n,cos(theta), 
sin(theta)) )

    
@interact
def _(n=(1,20)):
    plotNthRoots(n)
----------------------------------------------

<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">n&nbsp;</font></td><td>
        <table>
          <tr>
            <td>
              <div id="slider-n-0" style="margin:0px; margin-left: 1.0em; 
margin-right: 1.0em; width: 15.0em;"></div>
            </td>
            
            <td>
              <font color="black" id="slider-n-0-lbl"></font>
            </td>
          </tr>
        </table><script>
    (function() {
        var values = 
["1.0","1.0380761523046091","1.0761523046092183","1.1142284569138274","1.1523046092184366","1.1903807615230457","1.2284569138276549","1.266533066132264","1.3046092184368732","1.3426853707414823","1.3807615230460915","1.4188376753507006","1.4569138276553097","1.494989979959919","1.533066132264528","1.5711422845691372","1.6092184368737463","1.6472945891783555","1.6853707414829646","1.7234468937875738","1.761523046092183","1.799599198396792","1.8376753507014012","1.8757515030060103","1.9138276553106195","1.9519038076152286","1.9899799599198378","2.028056112224447","2.066132264529056","2.104208416833665","2.1422845691382744","2.1803607214428835","2.2184368737474927","2.256513026052102","2.294589178356711","2.33266533066132","2.3707414829659292","2.4088176352705384","2.4468937875751475","2.4849699398797567","2.523046092184366","2.561122244488975","2.599198396793584","2.6372745490981933","2.6753507014028024","2.7134268537074115","2.7515030060120207","2.78957915831663","2.827655310621239","2.865731462925848","2.9038076152304573","2.9418837675350664","2.9799599198396756","3.0180360721442847","3.056112224448894","3.094188376753503","3.132264529058112","3.1703406813627213","3.2084168336673304","3.2464929859719396","3.2845691382765487","3.322645290581158","3.360721442885767","3.398797595190376","3.4368737474949853","3.4749498997995945","3.5130260521042036","3.5511022044088127","3.589178356713422","3.627254509018031","3.66533066132264","3.7034068136272493","3.7414829659318585","3.7795591182364676","3.8176352705410768","3.855711422845686","3.893787575150295","3.931863727454904","3.9699398797595133","4.0080160320641225","4.046092184368732","4.084168336673341","4.12224448897795","4.160320641282559","4.198396793587168","4.236472945891777","4.2745490981963865","4.312625250500996","4.350701402805605","4.388777555110214","4.426853707414823","4.464929859719432","4.503006012024041","4.5410821643286505","4.57915831663326","4.617234468937869","4.655310621242478","4.693386773547087","4.731462925851696","4.769539078156305","4.8076152304609145","4.845691382765524","4.883767535070133","4.921843687374742","4.959919839679351","4.99799599198396","5.036072144288569","5.074148296593179","5.112224448897788","5.150300601202397","5.188376753507006","5.226452905811615","5.264529058116224","5.302605210420833","5.340681362725443","5.378757515030052","5.416833667334661","5.45490981963927","5.492985971943879","5.531062124248488","5.5691382765530975","5.607214428857707","5.645290581162316","5.683366733466925","5.721442885771534","5.759519038076143","5.797595190380752","5.8356713426853615","5.873747494989971","5.91182364729458","5.949899799599189","5.987975951903798","6.026052104208407","6.064128256513016","6.1022044088176255","6.140280561122235","6.178356713426844","6.216432865731453","6.254509018036062","6.292585170340671","6.33066132264528","6.3687374749498895","6.406813627254499","6.444889779559108","6.482965931863717","6.521042084168326","6.559118236472935","6.597194388777544","6.6352705410821535","6.673346693386763","6.711422845691372","6.749498997995981","6.78757515030059","6.825651302605199","6.863727454909808","6.9018036072144175","6.939879759519027","6.977955911823636","7.016032064128245","7.054108216432854","7.092184368737463","7.130260521042072","7.168336673346682","7.206412825651291","7.2444889779559","7.282565130260509","7.320641282565118","7.358717434869727","7.396793587174336","7.434869739478946","7.472945891783555","7.511022044088164","7.549098196392773","7.587174348697382","7.625250501001991","7.6633266533066005","7.70140280561121","7.739478957915819","7.777555110220428","7.815631262525037","7.853707414829646","7.891783567134255","7.9298597194388645","7.967935871743474","8.006012024048083","8.044088176352693","8.082164328657303","8.120240480961913","8.158316633266523","8.196392785571133","8.234468937875743","8.272545090180353","8.310621242484963","8.348697394789573","8.386773547094183","8.424849699398793","8.462925851703403","8.501002004008013","8.539078156312623","8.577154308617233","8.615230460921843","8.653306613226453","8.691382765531063","8.729458917835673","8.767535070140283","8.805611222444893","8.843687374749504","8.881763527054114","8.919839679358724","8.957915831663334","8.995991983967944","9.034068136272554","9.072144288577164","9.110220440881774","9.148296593186384","9.186372745490994","9.224448897795604","9.262525050100214","9.300601202404824","9.338677354709434","9.376753507014044","9.414829659318654","9.452905811623264","9.490981963927874","9.529058116232484","9.567134268537094","9.605210420841704","9.643286573146314","9.681362725450924","9.719438877755534","9.757515030060144","9.795591182364754","9.833667334669364","9.871743486973974","9.909819639278584","9.947895791583194","9.985971943887805","10.024048096192415","10.062124248497025","10.100200400801635","10.138276553106245","10.176352705410855","10.214428857715465","10.252505010020075","10.290581162324685","10.328657314629295","10.366733466933905","10.404809619238515","10.442885771543125","10.480961923847735","10.519038076152345","10.557114228456955","10.595190380761565","10.633266533066175","10.671342685370785","10.709418837675395","10.747494989980005","10.785571142284615","10.823647294589225","10.861723446893835","10.899799599198445","10.937875751503055","10.975951903807665","11.014028056112275","11.052104208416885","11.090180360721495","11.128256513026106","11.166332665330716","11.204408817635326","11.242484969939936","11.280561122244546","11.318637274549156","11.356713426853766","11.394789579158376","11.432865731462986","11.470941883767596","11.509018036072206","11.547094188376816","11.585170340681426","11.623246492986036","11.661322645290646","11.699398797595256","11.737474949899866","11.775551102204476","11.813627254509086","11.851703406813696","11.889779559118306","11.927855711422916","11.965931863727526","12.004008016032136","12.042084168336746","12.080160320641356","12.118236472945966","12.156312625250576","12.194388777555186","12.232464929859796","12.270541082164407","12.308617234469017","12.346693386773627","12.384769539078237","12.422845691382847","12.460921843687457","12.498997995992067","12.537074148296677","12.575150300601287","12.613226452905897","12.651302605210507","12.689378757515117","12.727454909819727","12.765531062124337","12.803607214428947","12.841683366733557","12.879759519038167","12.917835671342777","12.955911823647387","12.993987975951997","13.032064128256607","13.070140280561217","13.108216432865827","13.146292585170437","13.184368737475047","13.222444889779657","13.260521042084267","13.298597194388877","13.336673346693487","13.374749498998098","13.412825651302708","13.450901803607318","13.488977955911928","13.527054108216538","13.565130260521148","13.603206412825758","13.641282565130368","13.679358717434978","13.717434869739588","13.755511022044198","13.793587174348808","13.831663326653418","13.869739478958028","13.907815631262638","13.945891783567248","13.983967935871858","14.022044088176468","14.060120240481078","14.098196392785688","14.136272545090298","14.174348697394908","14.212424849699518","14.250501002004128","14.288577154308738","14.326653306613348","14.364729458917958","14.402805611222568","14.440881763527178","14.478957915831788","14.517034068136399","14.555110220441009","14.593186372745619","14.631262525050229","14.669338677354839","14.707414829659449","14.745490981964059","14.783567134268669","14.821643286573279","14.859719438877889","14.897795591182499","14.935871743487109","14.973947895791719","15.012024048096329","15.050100200400939","15.088176352705549","15.126252505010159","15.164328657314769","15.20240480961938","15.24048096192399","15.2785571142286","15.31663326653321","15.35470941883782","15.39278557114243","15.43086172344704","15.46893787575165","15.50701402805626","15.54509018036087","15.58316633266548","15.62124248497009","15.6593186372747","15.69739478957931","15.73547094188392","15.77354709418853","15.81162324649314","15.84969939879775","15.88777555110236","15.92585170340697","15.96392785571158","16.00200400801619","16.040080160320798","16.078156312625406","16.116232464930015","16.154308617234623","16.19238476953923","16.23046092184384","16.268537074148448","16.306613226453056","16.344689378757664","16.382765531062272","16.42084168336688","16.45891783567149","16.496993987976097","16.535070140280705","16.573146292585314","16.611222444889922","16.64929859719453","16.68737474949914","16.725450901803747","16.763527054108355","16.801603206412963","16.83967935871757","16.87775551102218","16.915831663326788","16.953907815631396","16.991983967936005","17.030060120240613","17.06813627254522","17.10621242484983","17.144288577154438","17.182364729459046","17.220440881763654","17.258517034068262","17.29659318637287","17.33466933867748","17.372745490982087","17.410821643286695","17.448897795591304","17.486973947895912","17.52505010020052","17.56312625250513","17.601202404809737","17.639278557114345","17.677354709418953","17.71543086172356","17.75350701402817","17.791583166332778","17.829659318637386","17.867735470941994","17.905811623246603","17.94388777555121","17.98196392785582","18.020040080160427","18.058116232465036","18.096192384769644","18.134268537074252","18.17234468937886","18.21042084168347","18.248496993988077","18.286573146292685","18.324649298597294","18.362725450901902","18.40080160320651","18.43887775551112","18.476953907815727","18.515030060120335","18.553106212424943","18.59118236472955","18.62925851703416","18.667334669338768","18.705410821643376","18.743486973947984","18.781563126252593","18.8196392785572","18.85771543086181","18.895791583166417","18.933867735471026","18.971943887775634","19.010020040080242","19.04809619238485","19.08617234468946","19.124248496994067","19.162324649298675","19.200400801603283","19.23847695390789","19.2765531062125","19.314629258517108","19.352705410821716","19.390781563126325","19.428857715430933","19.46693386773554","19.50501002004015","19.543086172344758","19.581162324649366","19.619238476953974","19.657314629258583","19.69539078156319","19.7334669338678","19.771543086172407","19.809619238477016","19.847695390781624","19.885771543086232","19.92384769539084","19.96192384769545","20.0"];
        setTimeout(function() {
            $('#slider-n-0').slider({
                step: 1,
                min: 0,
                max: 499,
                value: 0,
                change: function (e, ui) {
                    var position = ui.value;
                    if (values != null) {
                        $('#slider-n-0-lbl').text(values[position]);
                        interact(0, {variable: 'n', adapt_number: 1, value: 
encode64(position)}, 1);
                    }
                },
                slide: function (e, ui) {
                    if (values != null) {
                        $('#slider-n-0-lbl').text(values[ui.value]);
                    }
                }
            });
            if (values != null) {
                
$('#slider-n-0-lbl').text(values[$('#slider-n-0').slider('value')]);
            }
        }, 1);
    })();
    </script></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>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to