Skip to content

Instantly share code, notes, and snippets.

@fdlk
Last active August 31, 2017 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdlk/3cda774cc88653dfae912ca09cc0cd4b to your computer and use it in GitHub Desktop.
Save fdlk/3cda774cc88653dfae912ca09cc0cd4b to your computer and use it in GitHub Desktop.
R plot on homepage
  1. install python package manager pip in local user dir
> curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py”
> python get-pip.py --user
> rm get-pip.py
  1. install requests module in user dir
> .local/bin/pip install --user requests
  1. add update script to crontab
> crontab -e

In the editor, fill in:

0 4 * * * /srv/molgenis/run-ibd-script.py

(Script will run at 4 am every day)

  1. Create a token for user that can run the script Set its expiration date to null.

  2. put run-ibd-script.py in the molgenis user's home dir on the server, fill in the token you've just created.

  3. Add the plot script in the molgenis scripts plugin

Attribute Value
Script type R
Name run-ibd-script.py
Script content See script.R
Extension png
Generate token no
#!/usr/bin/python
#Demo script for IBD front page plot.
#Runs R script and writes resulting png image to resource dir
import requests
response = requests.get("http://localhost:8080/scripts/ibd-plot/run",
headers={"x-molgenis-token": "aaaaaaaaaaaaaaaaa"})
response.raise_for_status()
file = open('/srv/molgenis/apache-tomcat/webapps/ROOT/WEB-INF/classes/img/ibd.png', 'wb')
file.write(response.content)
file.close()
png('${outputFile}')
x<-seq(-pi,2*pi, by=0.01)
plot(x,sin(x * 2 * pi / (2 * pi) ), type='l')
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment