Auto execute cell on startup

65 views
Skip to first unread message

Robert Beezer

unread,
Sep 28, 2016, 1:02:36 PM9/28/16
to sage-cloud
I'm building  *.sagews  worksheets programatically, with many cells full of HTML, where I want the reader to only see the rendered version of the HTML.

I can hide the input cell with the  %hide  decorator.  However, I cannot get the  %auto  decorator to execute a cell (Sage or HTML) on reload with the most basic minimal example, as suggested by the "modes" options.  Should it be working?  Am I missing something?

I was accomplishing this months ago with the "x" marker at the end of the cell's UUID and prior to the Unicode marker (xFE20).  That device seems to no longer be active (and when I try to use it, cells hang with a flashing green segment on the cell divider).

So, perhaps with a reordering of the decorators, I'd like to accomplish:

%auto
%hide
%html
<p>Hello, world.</p>

Any suggestions?

Thanks,
Rob

Harald Schilly

unread,
Sep 28, 2016, 1:15:54 PM9/28/16
to sage-cloud
On Wed, Sep 28, 2016 at 7:02 PM, Robert Beezer <goo...@beezer.cotse.net> wrote:
> Any suggestions?

Please try if this does what you are looking for:

%auto
%html(hide=True)
<h1>
TEST
</h1>

Robert Beezer

unread,
Sep 28, 2016, 1:34:29 PM9/28/16
to sage-cloud
Thanks very much, Harald.  Certainly that accomplishes what I want/need when I run it.  Two experiments entirely within SMC:

(a) Execute the cell, delete output, save, close, open/load.

(b) Don't execute the cell, save, close, open/load.

Neither case produces any output/result.

Rob

William Stein

unread,
Sep 28, 2016, 1:57:44 PM9/28/16
to sage-cloud
On Wed, Sep 28, 2016 at 10:34 AM, Robert Beezer <goo...@beezer.cotse.net> wrote:
> Thanks very much, Harald. Certainly that accomplishes what I want/need when
> I run it. Two experiments entirely within SMC:
>
> (a) Execute the cell, delete output, save, close, open/load.
>
> (b) Don't execute the cell, save, close, open/load.
>
> Neither case produces any output/result.
>

%auto does not execute cells on open/load. It executes cells when the
Sage worksheet processes is started. If you just close and open the
file tab that has no impact on the sage worksheet process.

Just to clarify -- What is the real problem you are trying to solve?
Do you actually want to use %auto or do you really want the embed html
in a worksheet that is visible on open with no evaluation ever needed?

-- William

> Rob
>
>
> On Wednesday, September 28, 2016 at 10:15:54 AM UTC-7, Harald Schilly wrote:
>>
>> On Wed, Sep 28, 2016 at 7:02 PM, Robert Beezer <goo...@beezer.cotse.net>
>> wrote:
>> > Any suggestions?
>>
>> Please try if this does what you are looking for:
>>
>> %auto
>> %html(hide=True)
>> <h1>
>> TEST
>> </h1>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/42430a55-8c7e-444f-9b87-fb5f3942eaf2%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Best Regards,
William Stein

CEO, SageMath, Inc.

Robert Beezer

unread,
Sep 28, 2016, 2:11:15 PM9/28/16
to sage-cloud
On Wednesday, September 28, 2016 at 10:57:44 AM UTC-7, William Stein wrote:
Just to clarify -- What is the real problem you are trying to solve?

Thanks, William.  I'm building a converter to take MathBook XML source and turn it into SMC Sage worksheets.  I can write out almost anything, so I'm using xFE20, xFE21, UUIDs, decorators, etc. to match the necessary format.

I'd like to build a worksheet with a mix of HTML input cells and Sage code input cells.  The student/reader experience when the worksheet is "opened", will be that all the HTML is rendered and visible as output cells, but none of the Sage is executed yet (except perhaps some setup).

It is dawning on me as I write this, that maybe I just need to duplicate the HTML input inside an output cell with the thin JSON wrapper ("done", "html", etc.).  I'll experiment, but perhaps that'll accomplish what I need/want?  If you think so, and their are subleties I can't reverse-engineer, hints would be greatly appreciated.

Otherwise, building on my previous work and identifying changes in the worksheet format, it is going quite smoothly.

Rob

William Stein

unread,
Sep 28, 2016, 2:14:01 PM9/28/16
to sage-cloud
On Wed, Sep 28, 2016 at 11:11 AM, Robert Beezer <goo...@beezer.cotse.net> wrote:
> On Wednesday, September 28, 2016 at 10:57:44 AM UTC-7, William Stein wrote:
>>
>> Just to clarify -- What is the real problem you are trying to solve?
>
>
> Thanks, William. I'm building a converter to take MathBook XML source and
> turn it into SMC Sage worksheets. I can write out almost anything, so I'm
> using xFE20, xFE21, UUIDs, decorators, etc. to match the necessary format.
>
> I'd like to build a worksheet with a mix of HTML input cells and Sage code
> input cells. The student/reader experience when the worksheet is "opened",
> will be that all the HTML is rendered and visible as output cells, but none
> of the Sage is executed yet (except perhaps some setup).
>
> It is dawning on me as I write this, that maybe I just need to duplicate the
> HTML input inside an output cell with the thin JSON wrapper ("done", "html",
> etc.). I'll experiment, but perhaps that'll accomplish what I need/want?
> If you think so, and their are subleties I can't reverse-engineer, hints
> would be greatly appreciated.

That should work and be very easy to reverse engineer. Just take an
existing example and copy it. Be sure to make the output uuid's
unique. We really need to write a python library to do this asap
though... (maybe Hal Snyder <drx...@gmail.com> will...)

>
> Otherwise, building on my previous work and identifying changes in the
> worksheet format, it is going quite smoothly.
>
> Rob
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/20d80657-f21c-4b24-b1b5-993683b9feed%40googlegroups.com.

Robert Beezer

unread,
Sep 28, 2016, 2:21:30 PM9/28/16
to sage-cloud
On Wednesday, September 28, 2016 at 11:14:01 AM UTC-7, William Stein wrote:
That should work and be very easy to reverse engineer.  Just take an
existing example and copy it.  Be sure to make the output uuid's
unique.   We really need to write a python library to do this asap
though... (maybe Hal Snyder <drx...@gmail.com> will...)

Yes, small example works.  But I've got to sanitize the output version into JSON.  Dang, back to escape-character-hell for me. ;-)   Perhaps I'll find an XSL template/library for that, but I'm not optimistic.  I'm building fairly random UUID's right now, but I can do better perhaps by mixing in time and content.

Thanks, Harald and William for the quick replies.  There will be more questions/requests, but I think this will keep me productive for a good while longer.

Rob

 

William Stein

unread,
Sep 28, 2016, 2:30:43 PM9/28/16
to sage-cloud
On Wed, Sep 28, 2016 at 11:21 AM, Robert Beezer <goo...@beezer.cotse.net> wrote:
> On Wednesday, September 28, 2016 at 11:14:01 AM UTC-7, William Stein wrote:
>>
>> That should work and be very easy to reverse engineer. Just take an
>> existing example and copy it. Be sure to make the output uuid's
>> unique. We really need to write a python library to do this asap
>> though... (maybe Hal Snyder <drx...@gmail.com> will...)
>
>
> Yes, small example works. But I've got to sanitize the output version into
> JSON. Dang, back to escape-character-hell for me. ;-)

Python can easily do absolutely anything you want along those lines
automatically and robustly.

> Perhaps I'll find
> an XSL template/library for that, but I'm not optimistic. I'm building
> fairly random UUID's right now, but I can do better perhaps by mixing in
> time and content.

You should use a Python library for that.
https://docs.python.org/3/library/uuid.html

>
> Thanks, Harald and William for the quick replies. There will be more
> questions/requests, but I think this will keep me productive for a good
> while longer.
>
> Rob
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/3579889f-931b-40a1-a9b1-540eb15c2609%40googlegroups.com.

Harald Schilly

unread,
Sep 28, 2016, 2:40:36 PM9/28/16
to sage-cloud
On Wed, Sep 28, 2016 at 8:13 PM, William Stein <wst...@sagemath.com> wrote:
> We really need to write a python library to do this asap
> though... (maybe Hal Snyder <drx...@gmail.com> will...)

The ipynb2sagews I wrote has all the key abstractions for extracting
this into a lib:

https://github.com/sagemathinc/smc/blob/master/src/smc_pyutil/smc_pyutil/ipynb2sagews.py#L130

However, Robert is living in the XSLT world and just works with the
json-lines directly :-)

-- harald

Robert Beezer

unread,
Sep 28, 2016, 3:01:31 PM9/28/16
to sage-cloud
Right, I can definitely do some of this in Python, but I'm (stubbornly) trying to keep the CLI toolchain to one step (xsltproc).  Long-term, with a friendlier interface, or building within SMC, it may not make any difference.

XSL makes certain hard things extremely easy, and makes certain trivial things a PITA.  Gotta pick your poison, I guess...

William Stein

unread,
Sep 28, 2016, 3:02:55 PM9/28/16
to sage-cloud
On Wed, Sep 28, 2016 at 12:01 PM, Robert Beezer <goo...@beezer.cotse.net> wrote:
> Right, I can definitely do some of this in Python, but I'm (stubbornly)
> trying to keep the CLI toolchain to one step (xsltproc). Long-term, with a
> friendlier interface, or building within SMC, it may not make any
> difference.
>
> XSL makes certain hard things extremely easy, and makes certain trivial
> things a PITA. Gotta pick your poison, I guess...

Well you're using XML, so perhaps you're a glutton for punishment :-)

>
>
> On Wednesday, September 28, 2016 at 11:40:36 AM UTC-7, Harald Schilly wrote:
>>
>> On Wed, Sep 28, 2016 at 8:13 PM, William Stein <wst...@sagemath.com>
>> wrote:
>> > We really need to write a python library to do this asap
>> > though... (maybe Hal Snyder <drx...@gmail.com> will...)
>>
>> The ipynb2sagews I wrote has all the key abstractions for extracting
>> this into a lib:
>>
>>
>> https://github.com/sagemathinc/smc/blob/master/src/smc_pyutil/smc_pyutil/ipynb2sagews.py#L130
>>
>> However, Robert is living in the XSLT world and just works with the
>> json-lines directly :-)
>>
>> -- harald
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/982aa319-9214-49cb-b5a4-735c23a08d2b%40googlegroups.com.

Robert Beezer

unread,
Sep 28, 2016, 3:27:58 PM9/28/16
to sage-cloud
On Wednesday, September 28, 2016 at 12:02:55 PM UTC-7, William Stein wrote:
Well you're using XML, so perhaps you're a glutton for punishment :-)

Some days I think that.  But definitely not today. ;-)

kcrisman

unread,
Sep 29, 2016, 1:21:02 PM9/29/16
to sage-cloud

Well you're using XML, so perhaps you're a glutton for punishment :-)

Some days I think that.  But definitely not today. ;-)

Every day, Rob; every day. 

(FWIW, I agree that it's important for now to have a one-stop shop for authors in MBX.)
Reply all
Reply to author
Forward
0 new messages