Leaving the slider value editable

asked 2017-09-03 01:47:13 +0200

Bill Cook gravatar image

updated 2017-09-03 14:49:32 +0200

I would like to have a slider with an optional editable value. I have found that the first version gives me that option but the second just prints the value of "h" to the right (I can't click on it and edit it - it must be changed by messing with the slider).

@interact
def _(h=(0.1,(-1,1))):
    h

@interact
def _(h=slider(-1,1,default=0.1,step_size=0.001,label='$h=$')):
    h

I would just use the first block of code except that then I cannot give it a nicely formatted label or adjust other attributes (like step size).

Thanks!

Edit: I am running Windows 10. Using both Chrome and Microsoft Edge, I have the same issue. The first slider allows me to click on and edit the h value on the right while the second just displays the h value to the right. Here's the full html file I'm using to load up the interact...

<!DOCTYPE HTML>
<html>
  <title>Slider</title>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>SageMathCell</title>
    <script src="https://sagecell.sagemath.org/static/embedded_sagecell.js"></script>
    <script>$(function () {
    sagecell.makeSagecell({inputLocation:  '#mycell',
                           template:       sagecell.templates.minimal,
                           autoeval:       true,
                           linked:         true,
                           hide:           ["evalButton"]
                           //evalButtonText: 'Recompute'
                          });
    }); 
    </script>
  </head>

<body>

<div id="mycell"><script type="text/x-sage">
@interact
def _(h=(0.1,(-1,1))):
    h

@interact
def _(h=slider(-1,1,default=0.1,step_size=0.001,label='$h=$')):
    h
</script>
</div>

</body>
</html>
edit retag flag offensive close merge delete

Comments

Seems strange. Both versions worked for me in sagecell, cocalc and my local SageMath v8.0 (via both notebooks: classic and jupyter). Could this be a browser issue? Perhaps providing some more info could be helpful. Eg. SageMath version and browser.

fidbc gravatar imagefidbc ( 2017-09-03 08:24:14 +0200 )edit

I just edited my question adding in the html code to load the interact. I am using Chrome in Windows 10 (although Microsoft Edge does the same thing - and it's behaved the same way on other machines).

Bill Cook gravatar imageBill Cook ( 2017-09-03 14:50:41 +0200 )edit

Also, I posted a copy of this to my webpage...

https://mathsci2.appstate.edu/~cookwj/slider_test.html

Bill Cook gravatar imageBill Cook ( 2017-09-03 14:51:55 +0200 )edit

Sorry, was not understanding the question at all. Hadn't realized there is a spinner at the far right! Now that the question is clear, the behaviour seems to be inconsistent throughout the distinct interfaces (cocalc notebooks, sagecell and SageMath notebooks). Do you intend to use this via sagecell as in your example?

fidbc gravatar imagefidbc ( 2017-09-04 03:48:27 +0200 )edit

Yes. I've been making webpages for my calc 1 class to explore various ideas.

Bill Cook gravatar imageBill Cook ( 2017-09-04 04:40:50 +0200 )edit
1

This is really, really interesting, I've never noticed that thing on the right before either - I will let the Sage cell maintainer know about this, it's possible there is just some difference in the widgets called up here.

kcrisman gravatar imagekcrisman ( 2017-09-04 14:27:11 +0200 )edit

@kcrisman Thanks! I'm still quite new to Sage. It makes me feel better that I didn't miss some simple solution. It looks more like a bug than anything else.

Bill Cook gravatar imageBill Cook ( 2017-09-05 03:20:24 +0200 )edit

Note that the @interact implementations from the legacy Sage notebook (SageNB), SageCell and Jupyter are all different and independent. So, it is very well possible that things work with one implementation, but not the other. I just tried your examples in Jupyter, and they both work for me.

Jeroen Demeyer gravatar imageJeroen Demeyer ( 2017-09-29 13:03:17 +0200 )edit