Hello there
I found a solution:
<html>
<head>
<script>
sagecell.makeSagecell({
inputLocation: '#pyscript',
template: sagecell.templates.minimal,
});
</script>
<script src="sagesrc.js"></script>
</head>
<body onload="sagesrc()">
......
<div id="pyscript">
<script type="text/x-sage" src="somepgm.py"></script>
</div>
.......
</body>
</html>
The script:sagesrc.js:
function getPyScr(s) {
"use strict";
var xhr;
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
s.innerHTML = this.responseText;
}
};
xhr.open("GET", s.src, false); //If async is true it does not work
xhr.send();
}
function sagesrc() {
"use strict";
var scrObj, scrObjLen, i;
scrObj = document.scripts;
scrObjLen = scrObj.length;
for (i = 0; i < scrObjLen; i++) {
if (scrObj[i].type === "text/x-sage" && scrObj[i].src != "") {
getPyScr(scrObj[i]);
}
}
}
If the Python script, as in my case, is large it will take some time to load
But I can write it once and use it several times and in different places
Obviously, any improvement and / or comment is welcome
Jorge
El viernes, 6 de octubre de 2017, 22:15:47 (UTC-4), Jorge Manrique escribió:
>
> Hello Andrey
> neither of them works.
> As I read here
> <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script>, if
> the MIME type is text/x-sage then the src attribute is ignored and the code
> will be treated as an embedded data block that will not be processed by the
> browser.
> In relation to the bytecode, as you mention, it does not make sense.
>
> I'll try to use the makeSagecell callback attribute to load the program.
> AJAX style :-)
>
> If it works I will post it here
> Thanks again,
>
> George
>
> El jueves, 5 de octubre de 2017, 22:56:45 (UTC-4), Andrey Novoseltsev
> escribió:
>>
>> Have you tried these? I am quite sure that bytecode will not work since
>> both JS and Python side of SageMathCell operate with clear text code.
>> Loading files into script tags perhaps may work. What I know some people
>> have done in the past was loading long code via some short code snippet
>> that uses standard Python means of loading files/code, but that relies on
>> having your code hosted somewhere with a stable IP or DNS name.
>>
>>
>> On Tuesday, 3 October 2017 18:58:59 UTC-6, Jorge Manrique wrote:
>>>
>>> Hello everyone,
>>> I have an interactive program in Python. The program does some
>>> calculations with SageMath and graphs the results. The code is a bit long.
>>> I want to embed the program on a webpage using SageCell and I wonder if
>>> I can leave the Python program on the web server and use an external script:
>>>
>>> <head>
>>> . . . . . . .
>>> <script>
>>> sagecell.makeSagecell ({
>>> inputLocation: '#plot'
>>> })
>>> </ script>
>>> </ head>
>>> . . . . . . .
>>> <div id = "plot">
>>> <script type = "text / x-sage" src = "/ src / somegraph.py"> </
>>> script>
>>> </ div>
>>>
>>> or compile the program, for example, with CPython, and then include the
>>> bytecode in the second script above:
>>>
>>> <div id = "plot">
>>> <script type = "application / octet-stream">
>>> bytecode
>>> </ script>
>>> </ div>
>>>
>>> Any suggestions will be appreciated,
>>> Jorge
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"sage-cell" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sage-cell/4171f4cc-2d5a-4648-8c7a-09c683574e30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.