Hiding sage code in a sage cell (using interacts)

56 views
Skip to first unread message

Michael Miller

unread,
Apr 1, 2021, 9:20:10 PM4/1/21
to sage-cell
The following code hides the definition of f(x) while allowing its use in the interact input box.

===================================
<HTML>
<HEAD>
<script src="https://sagecell.sagemath.org/static/embedded_sagecell.js"></script>
<script>sagecell.makeSagecell({inputLocation: '.sage',
                                template: sagecell.templates.minimal,
                                autoeval:true,
                                hide: ["evalButton"],
                               });</script>
</HEAD>

<BODY>
<div class="sage">
<script type="text/x-sage">
def f(x):
   return x^2
@interact
def _(userinput=input_box(default="print(f(5))", label='', height=5), auto_update=false):
    exec(preparse(userinput))
</script>
</div>
</BODY>
</HTML>
====================================

1) It would be nice to have this incorporated into the native sagecell code.  In particular,
having a template sagecell.templates.hidden, and having the interact commands automatically appended would make this easier to use for those newly encountering sage cells.  I'm guessing that some combination of the sagecell code and the interact input_box code could accomplish all this.  I don't know enough about either to suggest how, but I'm happy to help where I can.

2) IMHO, having everything in a single html file makes customization easier (vs having to load code from github.)


Reply all
Reply to author
Forward
0 new messages