sagemath / sagecell

The Sage Cell Server---providing a way to embed Sage computations into any web page.
Other
201 stars 70 forks source link

Specifying a common kernel via key #546

Closed siefkenj closed 2 years ago

siefkenj commented 2 years ago

Is there a way to specify a key such that all Sage Cells initialized with the same key use the same kernel? I know one can specify linked cells by putting in a jQuery selector for all cells, but the way I am processing data, I don't know up front the ids of all Sage Cell divs.

Context

I am working on a rewrite of the Pretext Javascript backend in React. The current code traverses the DOM and replaces each sage cell with a react component which calls makeSageCell. As such, different Sage Cells don't know about eachother's ids (in fact, they could be created on the fly...). So I need a way to link cells via a common key, or to link cells after they have been created.

I didn't see anything like this in the documentation.

novoselt commented 2 years ago

I am pretty sure it is not covered in the documentation, but if you don't mind taking a look at the code https://github.com/sagemath/sagecell/blob/master/js/cell.js perhaps you can figure out what exactly k is doing, since it seems to me that it is used as a kernel identifier when a new cell is made. It seems that it is not exposed via makeSageCell, but you can probably call make directly. Sorry for being so vague - your JavaScript knowledge is likely to be much higher than mine, which I got just to the level of tweaking existing files when necessary ;-) Have you tried installing SageMathCell locally? If you don't care about security (because you are not running a public server) it should be relatively easy and would allow you to play with the code.

siefkenj commented 2 years ago

It appears that one cannot set k via a function call to makeSageCell, since k is set via internal calls...It should be an easy change to expose such functionality.

I am working on modifying the source, but I have two questions:

  1. Are there any tests for sagecell.js?
  2. Would you object to adding a package.json to the JS folder and using a more traditional npm install npm run build command flow for building the JS?
novoselt commented 2 years ago

No tests - there may have been a broken framework, but it likely got scrapped completely while I was refactoring the code to work with later versions of everything. If you can help set up something reliable - please do!

I do not object to adding anything useful and following best practices, as long as I can understand what is done and how I should continue working with it! I would actually love it if someone more proficient in JavaScript worked on the code beyond me making fixes when something breaks during upgrades.

siefkenj commented 2 years ago

I've tried to get the code to build for a few hours now with no luck :-(. I cannot get sage to build so I don't have the required JS dependencies (coming from the Jupyter project; I can find jQuery and underscore, etc. just fine). Would you be able to commit those dependencies to the source tree?

novoselt commented 2 years ago

I'd rather not, since it allows to stay as much in sync with Sage as possible. For building Sage itself you should be able to get quick help on sage-support or sage-develop.

siefkenj commented 2 years ago

Would you be able to attach them as a ZIP file here? (I.e., in this comment thread)

novoselt commented 2 years ago

build.zip This is for a build with Sage 9.5.