This page includes three examples of using WorkingWiki to edit and run actual code, and display the results.
Here's a little perl script:
Here's the perl script's output:
And here's the makefile that makes it run:
[Explanation of the makefile: The first line says that the output file should be remade whenever the perl script is changed. '>' is a UNIX directive that captures the output from the command to its left and puts it in the file to its right. The makefile invokes the perl interpreter to run the program "example.pl" and capture its output in "example-output.txt", but only if the program has changed since the last time the output file was updated. WorkingWiki uses this makefile every time it displays the output file, to make sure the file is up to date. So if you edit the perl code, and then save or preview this wiki page, the output file will be up to date when it appears in the page.]
If you're logged in to the wiki, you can change the script and watch the output change, it's fun!
(Because of software security issues, we can't let anonymous users edit the project files, sorry. If you're not logged in, you may want to click the "view source" tab above, to see how the files are embedded in the wiki page.)
Let's do this one with Python. We could do it with R, which is the main language in use on the theobio wikis, but we have special rules for using R, and we want to offer a self-contained example here.
So here's a Python script that makes a figure:
And here's the makefile to run the python script:
And now we ask for the figure and WorkingWiki makes it for us by running the script:
If you look at the source text of this page, you'll notice this example is in a separate project from the other one. This is just so we avoid the extra complexity of writing about how to combine makefiles in a single project.
R graphics example
Here is a simple example of how to do a figure with R, using the lalashan site's custom rules for using R. The custom rules make it simple: just define a .R file:
and request its output using just the right filename: