Skip to content

UtilizingExternalTools

William Stein edited this page Aug 18, 2018 · 16 revisions

Utilizing External Tools from CoCalc

This FAQ is all about connecting CoCalc to external resources. A highly related page is the FAQ for Programming Software in CoCalc, with information about C, R, Fortran, Java, Octave, et cetera. There is also a separate page for Sage and Jupyter.

Remember: if you don't find what you need, or if you'd like to ask a question, then please email [email protected] at any time. We'd love to hear from you! Please include a link (the URL address in your browser) to any relevant project or document, as part of your email.

List of Questions:

Question: I would like to ssh into my project.

This is explained on the page "All about Projects." Click here to jump there

Question: How can I sync my files with Dropbox or Google Drive?

We do not support Google Drive at present, but we plan to.

The Dropbox Linux command line client is preinstalled in CoCalc, and until recently you could use it to sync your files with Dropbox, following the instructions at https://www.dropbox.com/install-linux (again, noting that dropbox is already installed). However, Dropbox recently made a very sad decision to not support Linux (except ext4 unencrypted, which is a nonstarter), so Dropbox is no longer possible with CoCalc.

Question: I would like to push and pull from github using ssh.

First, despite the fact that you are accessing CoCalc through the internet, you are actually working in a highly restricted environment. Processes running inside a free project are not allowed to directly access the internet. (We do not allow such access for free users, since when we did, malicious users launched attacks on other computers from CoCalc.) Enable internet access by adding the "internet access" quota. See https://cocalc.com/policies/pricing.html

Once you have enabled network access for your project, to use ssh from CoCalc to connect to github you need to create an ssh key and explicitly allow that account/key access to github.

  1. Make a terminal: "+New --> Terminal"

  2. Create an ssh key public/private key pair by typing the command ssh-keygen.

  3. Copy .ssh/id_rsa.pub to github.

Question: I would like to edit files (with sync) or manipulate data files that are on some remote server that I have ssh access to

Unfortunately, SSHFS is no longer supported in CoCalc due to security issues.

If you really, really need sshfs support, feel free to write to us ([email protected]), and we may consider implementing a workaround if their is sufficient interest.

Again, the following instructions will not work no matter what.

WARNING: The following will only work if your project has outgoing network access, i.e., it says "Network access: true" under project settings. (Outgoing network access is blocked by default due to people using CoCalc as a platform to attack other computers. Please sign up for a membership in order to get network access.)

Suppose you have an account on some computer that you can ssh to, e.g, so this works for you:

To temporarily make the files at [email protected] available in a cloud project, open a Terminal and type

mkdir foo   # make any directory you want
sshfs [email protected]:path/to/files/ foo/

and type your password to login to [email protected]. You'll find that you can now use the files at path/to/files in [email protected] as if they were in the directory foo in your project. You can edit files (with sync), open and output data files, etc. When you're done, type

fusermount -u foo

to unmount foo. Whenever the project server is restarted, foo/ will also be unmounted. So you'll have to type sshfs [email protected]: foo/ to mount foo every once in a while.

NOTE: The files in foo/ will not be included in snapshots, because they are part of another filesystem, and the snapshot system is configured to not cross filesystem boundaries.

Question: I would like to use Emacs in a Terminal on Chrome. Help!

Chrome absolutely doesn't allow normal web applications to intercept certain keystrokes, which makes Emacs-in-a-terminal painful on some operating systems (esp. Linux/Windows). E.g., Ctrl-N brings up a new window, instead of going to the next line! (It is possible to eventually get around this by creating a Chrome extension, but I haven't done this yet.) In the meantime, you can install the CoCalc chrome app from the app store or on Linux, type google-chrome --app=https://cocalc.com/app to local the website as an app (if you use chromium instead, type chromium-browser --app=https://cocalc.com/app).

This is not a completely solution since in some cases, control-shift-minus and control-shift-plus still zoom in and out (on ChromeOS they zoom the entire desktop -- every window, all icons, the time, etc., in and out!). This is a major problem, because control-shift-minus is "undo" in emacs. The workaround I currently use is to put this in my .emacs file, and instead type "alt-u" for undo:

(define-key esc-map "u" 'undo)

Note that undo is also available by default through other key bindings, like C-x u and C-/. (Execute "M-x where-is undo".) So there are other options available.

How do I convert R markdown to a PDF file in CoCalc?

Run knit in R and pandoc as a shell command.

This is easier explained via an example:

Suppose you have an R markdown file "myproject.Rmd". In a .sagews worksheet, do

% r
library(markdown)
library(knitr)
knit("myproject.Rmd")

The last step above produces an ordinary markdown () file. The following shell command converts it to a PDF file.

%sh
pandoc myproject.md -o myproject.pdf

Note: make sure that the R and the sh cells have the same working directory.

I created an HTML form in a .sagews file using HTML, CSS and JS. How can I connect my form with my Python code?

To create a connection between your HTML form in a .sagews file created using HTML, CSS and JS, you need to use the worksheet.execute_code() function in your JS code.

Because worksheet.execute_code isn't a standard JS function, but special CoCalc function, you need to load your JS code with worksheet.execute_code(). In particular do NOT use

load('path/to/js/code.js')

but instead use

salvus.javascript(open('path/to/js/code.js').read())

For example in .sagews file suppose you created a div with id='myApp' as follows:

%html
<div id='myApp'>
....
    <div id="msgLog"></div>
    <div id="msgErr"></div>
</div>

Let's say your Python function will double x:

def myfunc(x):
    print(x*2)

In your JS code type:

worksheet.execute_code({
    code: 'myfunc(n)',
    data: {n: 2},
    preparse: true,
    cb: function(msg){
            if(msg.stdout){$('#myApp #msgLog').html(msg.stdout);}
            if(msg.stderr){$('#myApp #msgErr').html(msg.stderr);}
    }
});

Please note that myfunc() doesn't return anything. On the contrary, it uses print() to send output. This is because JS and python are different languages, and you can't just use return in your Python function to return some answer. stdout in JS code means standard output stream. That is, the print function in your Python code places the result of myfunc() in the output stream. That's why you need to use print() but not return() in your Python code.

Also, if your Python code will raise some exception, then it will result in output to stderr -- the standard error stream. If you JS code (as in the example above) catches stderr, you can get any error message from your Python code.

Question: I would like to use a customized version of FriCAS in a worksheet

The following Sage/Python command modifies the PATH variable to include $HOME/bin. Sage looks for the fricas executable in this PATH:

os.environ['PATH'] = '%s/bin:%s'%(os.environ['HOME'],os.environ['PATH'])

Restart the worksheet to make sure the new version of FriCAS is started.

Question: Is Scilab broken?

No, the Java stacktrace only happens because there is no graphical interface available due to the fact that there is no graphical interface ;-)

Type

scilab-adv-cli

or

scilab-cli

or

scilab -nw

Question: How can I use the fish shell with correctly working Home/End keys?

You can automatically span a new process instead of the default bash and you have to set the TERM env variable correctly to use xterm! I.e.

  1. Click on the rocket-icon in a terminal

  2. Add this to the setup file:

    source ~/.bashrc
    export TERM=xterm-256color
    exec fish
    

Next time you launch this terminal, or restart it via exit and pressing the return-key, this setup file will be evaluated and you'll end up in the fish shell with the correct TERM env variable set.

Question: I'm using the vim pentadactyl plugin, and the editor isn't working.

The Pentadactyl plugin is not compatible with the Codemirror editor in CoCalc. You can disable Pentadactyl for a particular page, perhaps by pressing Control+Z. SagemMathCloud has it's own Vim bindings for worksheets and editing files; to enable it, go to setting (click the gear by your name in the upper right), then select Vim next to Editor --> Bindings.

Question: My vim key bindings aren't working in CoCalc.

If you have a browser extension that uses the vim keys it may intercept the 'Esc' character, preventing you from switching to command mode in SageMath Cloud. Either remap 'Esc' to a different key for the browser extension or disable the extension on cocalc.com.

Question: I want to XXX, but I don't see XXX above.

Do not hesitate to email THE LINK TO YOUR PROJECT TO [email protected] or https://groups.google.com/forum/?fromgroups#!forum/sage-cloud

Analytics

Clone this wiki locally