dashboard lab is a free sample app to help me and hope other to understand how to make a frontend app over an opencpu architecture
how to build chartreader package under rstudio
the docker env was taken from this project https://github.com/technologiestiftung/fhpredict-opencpu
launch the opencpu image
docker-compose up -d
go to rstudio on http://localhost:8004/rstudio/
open the workspace chartreader
then go to build sources
then install the package and restart opencpu server
go to
then list your avalaible packe as below
Example: how to list charteader avalable endpoints
use ../user/opencpu/library/chartreader/R/boxplotcars
retrieve the result from the opencpu session
http://localhost//ocpu/tmp/x04337ea1bc33fe/R/.val/json?auto_json=T
don't forget to use auto_json=T filter if you don't want any malformed json for frontend devloppement
the sample highchart data.json is from https://www.highcharts.com/docs/getting-started/your-first-chart
The url of the package to call as json
http://localhost/ocpu/user/opencpu/library/mysamplepack/R/test/json
install package
cd /home/opencpu
R CMD INSTALL mysamplepack_0.1.0.tar.gz
cd app
npm run serve
go to http://localhost:8087/
and have fun !
enter login bigdata password datascience
https://rwebapps.ocpu.io/appdemo/www/plot.html
https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/boxplot.stats.html
https://github.com/rwebapps/appdemo/blob/master/R/randomplot.R
https://www.tutorialspoint.com/r/r_boxplots.htm
https://github.com/technologiestiftung/fhpredict-opencpu
https://hub.docker.com/r/opencpu/rstudio/
https://cran.r-project.org/web/packages/jsonlite/jsonlite.pdf
http://tuxette.nathalievilla.org/?p=1696
https://github.com/rwebapps/appdemo
https://blog.learningtree.com/creating-web-service-in-r/
http://seankross.com/notes/dpqr/
https://www.tutorialspoint.com/r/r_normal_distribution.htm
use "auto_unbox=T" as an option to the json endpoint
- Introduction
- install docker image
- build chartreader package
- test package
- sample
- serve the front end app
- webography
- opencpu with docker
Basic instructions about opencpu can be found here: www.opencpu.org/download.html
Now simply open http://localhost/ocpu/ and http://localhost/rstudio/ in your browser! Login via rstudio with user: opencpu (passwd: opencpu) to build or install apps.
!Hint: Since PORT 80 is used we need to use the 8004 PORT:
- opencpu api explorer is at http://localhost:8004/ocpu
- rstudio is at http://localhost:8004/rstudio (user: opencpu password: opencpu)
The folder ./workspace
is mapped into the working directory of the container at /home/opencpu
all files in workspace will directly we available in the container and in RStudio. If you do changes in RStudio to these files they will be saved to your local drive.
!Hint: Don't copy the $
in the commands. It is for marking the input.
Start it:
$ cd path/to/repository
# if you didn't do changes to opencpu/Dockerfile.dev
# You can ommit the --build flag
$ docker-compose up --build
> Starting opencpu-docker_opencpu_1 ... done
> Attaching to opencpu-docker_opencpu_1
> opencpu_1 | * Starting periodic command scheduler cron
> opencpu_1 | ...done.
> …
Open your browser and start hacking
Stop it:
End the terminal session by hitting CTRL + C
and stop the containers (all changes other the done to the files in workspace:/home/opencpu
will be lost)
$ docker-compose down
> Stopping opencpu-docker_opencpu_1 ... done
> Removing opencpu-docker_opencpu_1 ... done
> Removing network opencpu-docker_default
Start a bash session within the container run. Be aware that all changes will be lost when the container gets stopped:
$ docker ps
> CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
> 50ad1d0af4c6 opencpu-docker_opencpu "/bin/sh -c 'service…" 22 minutes ago Up 22 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:8004->8004/tcp, 443/tcp opencpu-docker_opencpu_1
Use the Container ID or the NAMES property to run the bash session.
$ docker exec -it <CONTANER ID | NAME> bash
> sends you into a session in the container
> …
To add additional R packages to the container image you have to edit the file opencpu/Dockerfile.dev
.
Add a line containing your desired package like this one. Please add the ref parameter to the install (in this case the @v0.1.0-beta
):
RUN R -e "devtools::install_github(\"technologiestiftung/[email protected]\")"
Then run again a docker-compose up --build
from the root of the repo.
The image is based on Ubuntu 18.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
To install other dependencies RUN
the usual apt-get
commands in the docker file.
!Hint: The commands don't allow an interactive prompt. Add the -y
flag to accept all Y/n
questions.
For example to install curl
you could RUN
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
The opencpu API docs can be found here.
The code below assumes the fhpredict
package is installed and the opencpu container is running.
Description: The function simple(str = '{"foo":"bah"}')
of the package fhpredict
takes a JSON string as argument. (Needs to be properly escaped.)
Requests using CURL
curl -X POST "http://localhost:8004/ocpu/library/fhpredict/R/simple" \
-H "Content-Type: application/json" \
--data-raw "$body"
Header Parameters: Content-Type should respect the following schema:
{
"type": "string",
"enum": [
"application/json"
],
"default": "application/json"
}
Body Parameters: body should respect the following schema:
{
"type": "string",
"default": "{\n \"str\": \"{\\\"foo\\\":12}\"\n}"
}
Description: The POST request returns something like the example below. These are new endpoints that are generated during runtime and will be discarded on restart. The result of the calculation can be found under the .val
endpoint. See also https://www.opencpu.org/api.html#api-session
/ocpu/tmp/x0aa062559b9cf1/R/.val
/ocpu/tmp/x0aa062559b9cf1/R/simple
/ocpu/tmp/x0aa062559b9cf1/stdout
/ocpu/tmp/x0aa062559b9cf1/source
/ocpu/tmp/x0aa062559b9cf1/console
/ocpu/tmp/x0aa062559b9cf1/info
/ocpu/tmp/x0aa062559b9cf1/files/DESCRIPTION
Requests using CURL
curl -X GET "http://localhost:8004/ocpu/tmp/x0aa062559b9cf1/R/.val"
Description: From the api docs.
The
/ocpu/info
endpoint shows the output of sessionInfo() from the main (web server) process. This can be helpful for debugging. The /ocpu/test URL gives you a handy testing web page to perform server requests.
See also https://www.opencpu.org/api.html#api-libraries
Requests using CURL
curl -X GET "http://localhost:8004/ocpu/info"
Description: Show information about the package fhpredict package. See also https://www.opencpu.org/api.html#api-libraries
Requests using CURL
curl -X GET "http://localhost:8004/ocpu/library/fhpredict/info"