This is an automated email from the ASF dual-hosted git repository. zjffdu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push: new 100cdb6 [ZEPPELIN-5481] Support to run R interpreter in yarn mode with customized conda env 100cdb6 is described below commit 100cdb6021f3f8132ca9b3ed3beff507125cce78 Author: Jeff Zhang <zjf...@apache.org> AuthorDate: Mon Aug 9 22:28:25 2021 +0800 [ZEPPELIN-5481] Support to run R interpreter in yarn mode with customized conda env ### What is this PR for? Simple PR to make R interpreter run in yarn mode with customized conda env. ### What type of PR is it? [ Feature ] ### Todos * [ ] - Task ### What is the Jira issue? * https://issues.apache.org/jira/browse/ZEPPELIN-5481 ### How should this be tested? * Manually tested ### Screenshots (if appropriate)  ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Jeff Zhang <zjf...@apache.org> Closes #4199 from zjffdu/ZEPPELIN-5481 and squashes the following commits: f5f5058794 [Jeff Zhang] update doc cbf51622a2 [Jeff Zhang] use File.separator 9fbf2626aa [Jeff Zhang] [ZEPPELIN-5481] Support to run R interpreter in yarn mode with customized conda env --- docs/interpreter/r.md | 160 +++++++- .../3. R Conda Env in Yarn Mode_2GB9HRSH9.zpln | 401 +++++++++++++++++++++ .../java/org/apache/zeppelin/r/IRInterpreter.java | 15 + 3 files changed, 557 insertions(+), 19 deletions(-) diff --git a/docs/interpreter/r.md b/docs/interpreter/r.md index ef61f4b..2d39126 100644 --- a/docs/interpreter/r.md +++ b/docs/interpreter/r.md @@ -27,7 +27,7 @@ limitations under the License. [R](https://www.r-project.org) is a free software environment for statistical computing and graphics. -To run R code and visualize plots in Apache Zeppelin, you will need R on your master node (or your dev laptop). +To run R code and visualize plots in Apache Zeppelin, you will need R on your zeppelin server node (or your dev laptop). + For Centos: `yum install R R-devel libcurl-devel openssl-devel` + For Ubuntu: `apt-get install r-base` @@ -87,9 +87,9 @@ Zeppelin supports R language in 3 interpreters <tr> <td>%r.r</td> <td>RInterpreter</td> - <td>Vanilla r interpreter, with least dependencies, only R environment installed is required. - It is always recommended to use the fully qualified interpreter name <code>%r.r</code>code>, because <code>%r</code> is ambiguous, - it could mean both <code>%spark.r</code> and <code>%r.r</code></td> + <td>Vanilla r interpreter, with least dependencies, only R environment and knitr are required. + It is always recommended to use the fully qualified interpreter name <code>%r.r</code>, because <code>%r</code> is ambiguous, + it could mean <code>%spark.r</code> when current note's default interpreter is <code>%spark</code> and <code>%r.r</code> when the default interpreter is <code>%r</code></td> </tr> <tr> <td>%r.ir</td> @@ -103,7 +103,7 @@ Zeppelin supports R language in 3 interpreters </tr> </table> -If you want to use R with Spark, it is almost the same via `%spark.r`, `%spark.ir` & `%spark.shiny` . You can refer Spark Interpreter docs for more details. +If you want to use R with Spark, it is almost the same via `%spark.r`, `%spark.ir` & `%spark.shiny` . You can refer Spark interpreter docs for more details. ## Configuration @@ -139,38 +139,66 @@ If you want to use R with Spark, it is almost the same via `%spark.r`, `%spark.i <td>500px</td> <td>IFrame height of Shiny App</td> </tr> + <tr> + <td>zeppelin.R.shiny.portRange</td> + <td>:</td> + <td>Shiny app would launch a web app at some port, this property is to specify the portRange via format 'start':'end', e.g. '5000:5001'. By default it is ':' which means any port.</td> + </tr> + <tr> + <td>zeppelin.R.maxResult</td> + <td>1000</td> + <td>Max number of dataframe rows to display when using z.show</td> + </tr> </table> -## Using the R Interpreter(`%r.r` & `%r.ir`) +## Interpreter binding mode + +The default [interpreter binding mode](../usage/interpreter/interpreter_binding_mode.html) is `globally shared`. That means all notes share the same R interpreter. +So we would recommend you to ues `isolated per note` which means each note has own R interpreter without affecting each other. But it may run out of your machine resource if too many R +interpreters are created. You can [run R in yarn mode](../interpreter/r.html#run-r-in-yarn-cluster) to avoid this problem. + +## How to use R Interpreter + +There are two different implementations of R interpreters: `%r.r` and `%r.ir`. -By default, the R Interpreter appears as two Zeppelin Interpreters, `%r.r` and `%r.ir`. +* Vanilla R Interpreter(`%r.r`) behaves like an ordinary REPL and use SparkR to communicate between R process and JVM process. It requires `knitr` to be installed. +* IRKernel R Interpreter(`%r.ir`) behaves like using IRKernel in Jupyter notebook. It is based on [jupyter interpreter](jupyter.html). Besides jupyter interpreter's prerequisites, [IRkernel](https://github.com/IRkernel/IRkernel) needs to be installed as well. -`%r.r` behaves like an ordinary REPL and use SparkR to communicate between R process and JVM process. -`%r.ir` use IRKernel underneath, it behaves like using IRKernel in Jupyter notebook. +Take a look at the tutorial note `R Tutorial/1. R Basics` for how to write R code in Zeppelin. -R basic expression +### R basic expressions + +R basic expressions are supported in both `%r.r` and `%r.ir`. <img class="img-responsive" src="{{BASE_PATH}}/assets/themes/zeppelin/img/docs-img/r_basic.png" width="800px"/> -R base plotting is fully supported +### R base plotting + +R base plotting is supported in both `%r.r` and `%r.ir`. <img class="img-responsive" src="{{BASE_PATH}}/assets/themes/zeppelin/img/docs-img/r_plotting.png" width="800px"/> -Besides R base plotting, you can use other visualization library, e.g. `ggplot` and `googlevis` +### Other plotting + +Besides R base plotting, you can use other visualization libraries in both `%r.r` and `%r.ir`, e.g. `ggplot` and `googleVis` <img class="img-responsive" src="{{BASE_PATH}}/assets/themes/zeppelin/img/docs-img/r_ggplot.png" width="800px"/> <img class="img-responsive" src="{{BASE_PATH}}/assets/themes/zeppelin/img/docs-img/r_googlevis.png" width="800px"/> -You can also use `z.show()` in `%r.ir` to visualize the dataframe, e.g. +### z.show + +`z.show()` is only available in `%r.ir` to visualize R dataframe, e.g. <img class="img-responsive" src="{{BASE_PATH}}/assets/themes/zeppelin/img/docs-img/r_zshow.png" width="800px"/> - +By default, `z.show` would only display 1000 rows, you can specify the maxRows via `z.show(df, maxRows=2000)` + ## Make Shiny App in Zeppelin [Shiny](https://shiny.rstudio.com/tutorial/) is an R package that makes it easy to build interactive web applications (apps) straight from R. -For developing one Shiny App in Zeppelin, you need to at least 3 paragraphs (server paragraph, ui paragraph and run type paragraph) +`%r.shiny` is used for developing R shiny app in Zeppelin notebook. It only works when IRKernel Interpreter(`%r.ir`) is enabled. +For developing one Shiny App in Zeppelin, you need to write at least 3 paragraphs (server type paragraph, ui type paragraph and run type paragraph) * Server type R shiny paragraph @@ -252,13 +280,14 @@ ui <- fluidPage( ``` -After executing the run type R shiny paragraph, the shiny app will be launched and embedded as Iframe in paragraph. +After executing the run type R shiny paragraph, the shiny app will be launched and embedded as iframe in paragraph. +Take a look at the tutorial note `R Tutorial/2. Shiny App` for how to develop R shiny app. <img class="img-responsive" src="{{BASE_PATH}}/assets/themes/zeppelin/img/docs-img/r_shiny.png" width="800px"/> -### Run multiple shiny app +### Run multiple shiny apps -If you want to run multiple shiny app, you can specify `app` in paragraph local property to differentiate shiny app. +If you want to run multiple shiny apps, you can specify `app` in paragraph local property to differentiate different shiny apps. e.g. @@ -272,4 +301,97 @@ e.g. ```r %r.shiny(type=run, app=app_1) -``` \ No newline at end of file +``` + +## Run R in yarn cluster + +Zeppelin support to [run interpreter in yarn cluster](../quickstart/yarn.html). But there's one critical problem to run R in yarn cluster: how to manage the R environment in yarn container. +Because yarn cluster is a distributed cluster which is composed of many nodes, and your R interpreter can start in any node. +It is not practical to manage R environment in each node. + +So in order to run R in yarn cluster, we would suggest you to use conda to manage your R environment, and Zeppelin can ship your +R conda environment to yarn container, so that each R interpreter can have its own R environment without affecting each other. + +To be noticed, you can only run IRKernel interpreter(`%r.ir`) in yarn cluster. So make sure you include at least the following prerequisites in the below conda env: + +* python +* jupyter +* grpcio +* protobuf +* r-base +* r-essentials +* r-irkernel + +`python`, `jupyter`, `grpcio` and `protobuf` are required for [jupyter interpreter](../interpreter/jupyter.html), because IRKernel interpreter is based on [jupyter interpreter](../interpreter/jupyter.html). Others are for R runtime. + +Following are instructions of how to run R in yarn cluster. You can find all the code in the tutorial note `R Tutorial/3. R Conda Env in Yarn Mode`. + + +### Step 1 + +We would suggest you to use conda pack to create archive of conda environment. + +Here's one example of yaml file which is used to generate a conda environment with R and some useful R libraries. + +* Create a yaml file for conda environment, write the following content into file `r_env.yml` + +```text +name: r_env +channels: + - conda-forge + - defaults +dependencies: + - python=3.7 + - jupyter + - grpcio + - protobuf + - r-base=3 + - r-essentials + - r-evaluate + - r-base64enc + - r-knitr + - r-ggplot2 + - r-irkernel + - r-shiny + - r-googlevis +``` + +* Create conda environment via this yaml file using either `conda` or `mamba` + +```bash + +conda env create -f r_env.yml +``` + +```bash + +mamba env create -f r_env.yml +``` + + +* Pack the conda environment using `conda` + +```bash + +conda pack -n r_env +``` + +### Step 2 + +Specify the following properties to enable yarn mode for R interpreter via [inline configuration](../usage/interpreter/overview.html#inline-generic-configuration) + +``` +%r.conf + +zeppelin.interpreter.launcher yarn +zeppelin.yarn.dist.archives hdfs:///tmp/r_env.tar.gz#environment +zeppelin.interpreter.conda.env.name environment +``` + +`zeppelin.yarn.dist.archives` is the R conda environment tar file which is created in step 1. This tar will be shipped to yarn container and untar in the working directory of yarn container. +`hdfs:///tmp/r_env.tar.gz` is the R conda archive file you created in step 2. `environment` in `hdfs:///tmp/r_env.tar.gz#environment` is the folder name after untar. +This folder name should be the same as `zeppelin.interpreter.conda.env.name`. + +### Step 3 + +Now you can use run R interpreter in yarn container and also use any R libraries you specify in step 1. diff --git a/notebook/R Tutorial/3. R Conda Env in Yarn Mode_2GB9HRSH9.zpln b/notebook/R Tutorial/3. R Conda Env in Yarn Mode_2GB9HRSH9.zpln new file mode 100644 index 0000000..288dc22 --- /dev/null +++ b/notebook/R Tutorial/3. R Conda Env in Yarn Mode_2GB9HRSH9.zpln @@ -0,0 +1,401 @@ +{ + "paragraphs": [ + { + "text": "%md\n\nThis tutorial is for how to use customize R runtime environment via conda in yarn mode.\nIn this approach, the R interpreter runs in yarn container instead of in the zeppelin server host. And remmeber this only works for IRKernel(`%r.ir`) but not for vanilla R(`%r.r`), so make sure you include the following python packages in your conda env.\n* python\n* jupyter\n* grpcio\n* protobuf\n* r-base\n* r-essentials\n* r-irkernel\n\n\n\n", + "user": "anonymous", + "dateUpdated": "2021-08-09 10:55:29.815", + "progress": 0, + "config": { + "tableHide": false, + "editorSetting": { + "language": "markdown", + "editOnDblClick": true, + "completionKey": "TAB", + "completionSupport": false + }, + "colWidth": 12.0, + "editorMode": "ace/mode/markdown", + "fontSize": 9.0, + "editorHide": false, + "title": false, + "results": {}, + "enabled": true + }, + "settings": { + "params": {}, + "forms": {} + }, + "results": { + "code": "SUCCESS", + "msg": [ + { + "type": "HTML", + "data": "<div class=\"markdown-body\">\n<p>This tutorial is for how to use customize R runtime environment via conda in yarn mode.<br />\nIn this approach, the R interpreter runs in yarn container instead of in the zeppelin server host. And remmeber this only works for IRKernel(<code>%r.ir</code>) but not for vanilla R(<code>%r.r</code>), so make sure you include the following python packages in your conda env.</p>\n<ul>\n<li>python</li>\n<li>jupyter</li>\n<li>grpcio</li>\n<li>prot [...] + } + ] + }, + "apps": [], + "runtimeInfos": {}, + "progressUpdateIntervalMs": 500, + "jobName": "paragraph_1624111096909_1969681448", + "id": "paragraph_1616510705826_532544979", + "dateCreated": "2021-06-19 21:58:16.909", + "dateStarted": "2021-08-09 10:55:29.817", + "dateFinished": "2021-08-09 10:55:29.825", + "status": "FINISHED" + }, + { + "title": "Create R conda env", + "text": "%sh\n\n# make sure you have miniconda, conda-pack and mamba installed.\n# install miniconda: https://docs.conda.io/en/latest/miniconda.html\n# install conda-pack: https://conda.github.io/conda-pack/\n# install mamba: https://github.com/mamba-org/mamba\n\necho \"name: r_env\nchannels:\n - conda-forge\n - defaults\ndependencies:\n - python=3.7 \n - jupyter\n - grpcio\n - protobuf\n - r-base=3\n - r-essentials\n - r-evaluate\n - r-base64enc\n - r-knitr\n - r-ggplot2\ [...] + "user": "anonymous", + "dateUpdated": "2021-08-09 10:55:29.917", + "progress": 0, + "config": { + "editorSetting": { + "language": "sh", + "editOnDblClick": false, + "completionKey": "TAB", + "completionSupport": false + }, + "colWidth": 12.0, + "editorMode": "ace/mode/sh", + "fontSize": 9.0, + "title": true, + "results": {}, + "enabled": true + }, + "settings": { + "params": {}, + "forms": {} + }, + "results": { + "code": "SUCCESS", + "msg": [ + { + "type": "TEXT", + "data": "\nRemove all packages in environment /mnt/disk1/jzhang/miniconda3/envs/r_env:\n\npkgs/main/noarch \npkgs/main/linux-64 \npkgs/r/linux-64 \nconda-forge/noarch \npkgs/r/noarch \nconda-forge/linux-64 \nTransaction\n\n Prefix: /mnt/disk1/jzhang/miniconda3/envs/r_env\n\n Updating specs:\n\n - python=3.7\n - jupyter\n - grpcio\n - protobuf\n - r-base=3\n - r-essentials\n - r-evaluate\n - r-base64enc\n - r-knit [...] + } + ] + }, + "apps": [], + "runtimeInfos": {}, + "progressUpdateIntervalMs": 500, + "jobName": "paragraph_1624111096910_1941489893", + "id": "paragraph_1617163651950_276096757", + "dateCreated": "2021-06-19 21:58:16.910", + "dateStarted": "2021-08-09 10:55:29.920", + "dateFinished": "2021-08-09 10:55:59.548", + "status": "FINISHED" + }, + { + "title": "Create R conda tar", + "text": "%sh\n\nrm -rf r_env.tar.gz\nconda pack -n r_env\n", + "user": "anonymous", + "dateUpdated": "2021-08-09 10:55:59.555", + "progress": 0, + "config": { + "editorSetting": { + "language": "sh", + "editOnDblClick": false, + "completionKey": "TAB", + "completionSupport": false + }, + "colWidth": 12.0, + "editorMode": "ace/mode/sh", + "fontSize": 9.0, + "title": true, + "results": {}, + "enabled": true + }, + "settings": { + "params": {}, + "forms": {} + }, + "results": { + "code": "SUCCESS", + "msg": [ + { + "type": "TEXT", + "data": "Collecting packages...\nPacking environment at '/mnt/disk1/jzhang/miniconda3/envs/r_env' to 'r_env.tar.gz'\n\r[ ] | 0% Completed | 0.0s\r[ ] | 0% Completed | 0.1s\r[ ] | 0% Completed | 0.2s\r[ ] | 0% Completed | 0.3s\r[ ] | 0% Completed | 0.4s\r[ [...] + } + ] + }, + "apps": [], + "runtimeInfos": {}, + "progressUpdateIntervalMs": 500, + "jobName": "paragraph_1624111096910_883123029", + "id": "paragraph_1617170106834_1523620028", + "dateCreated": "2021-06-19 21:58:16.910", + "dateStarted": "2021-08-09 10:55:59.557", + "dateFinished": "2021-08-09 10:57:09.103", + "status": "FINISHED" + }, + { + "title": "Upload R conda tar to hdfs (Optional)", + "text": "%sh\n\nhadoop fs -rmr /tmp/r_env.tar.gz\nhadoop fs -put r_env.tar.gz /tmp\n# The python conda tar should be publicly accessible by others, so need to change permission here.\nhadoop fs -chmod 644 /tmp/r_env.tar.gz\n", + "user": "anonymous", + "dateUpdated": "2021-08-09 10:57:09.143", + "progress": 0, + "config": { + "editorSetting": { + "language": "sh", + "editOnDblClick": false, + "completionKey": "TAB", + "completionSupport": false + }, + "colWidth": 12.0, + "editorMode": "ace/mode/sh", + "fontSize": 9.0, + "title": true, + "results": {}, + "enabled": true + }, + "settings": { + "params": {}, + "forms": {} + }, + "results": { + "code": "SUCCESS", + "msg": [ + { + "type": "TEXT", + "data": "rmr: DEPRECATED: Please use '-rm -r' instead.\n21/08/09 10:57:10 INFO fs.TrashPolicyDefault: Moved: 'hdfs://emr-header-1.cluster-46718:9000/tmp/r_env.tar.gz' to trash at: hdfs://emr-header-1.cluster-46718:9000/user/hadoop/.Trash/Current/tmp/r_env.tar.gz1628477830555\n" + } + ] + }, + "apps": [], + "runtimeInfos": {}, + "progressUpdateIntervalMs": 500, + "jobName": "paragraph_1624111096911_217029483", + "id": "paragraph_1617163700271_1335210825", + "dateCreated": "2021-06-19 21:58:16.911", + "dateStarted": "2021-08-09 10:57:09.148", + "dateFinished": "2021-08-09 10:57:16.029", + "status": "FINISHED" + }, + { + "title": "Configure R Interpreter", + "text": "%r.conf\n\n# set zeppelin.interpreter.launcher to be yarn, so that R interpreter run in yarn container, \n# otherwise R interpreter run as local process in the zeppelin server host.\nzeppelin.interpreter.launcher yarn\n\n# zeppelin.yarn.dist.archives can be either local file or hdfs file\nzeppelin.yarn.dist.archives hdfs:///tmp/r_env.tar.gz#environment\n\nzeppelin.interpreter.conda.env.name environment\n\n", + "user": "anonymous", + "dateUpdated": "2021-08-09 10:57:16.052", + "progress": 0, + "config": { + "editorSetting": { + "language": "text", + "editOnDblClick": false, + "completionKey": "TAB", + "completionSupport": false + }, + "colWidth": 12.0, + "editorMode": "ace/mode/text", + "fontSize": 9.0, + "title": true, + "results": {}, + "enabled": true + }, + "settings": { + "params": {}, + "forms": {} + }, + "results": { + "code": "SUCCESS", + "msg": [] + }, + "apps": [], + "runtimeInfos": {}, + "progressUpdateIntervalMs": 500, + "jobName": "paragraph_1624111096911_1248279804", + "id": "paragraph_1616750271530_2029224504", + "dateCreated": "2021-06-19 21:58:16.911", + "dateStarted": "2021-08-09 10:57:16.057", + "dateFinished": "2021-08-09 10:57:16.058", + "status": "FINISHED" + }, + { + "title": "Base plotting", + "text": "%r.ir\n\npairs(iris)\n", + "user": "anonymous", + "dateUpdated": "2021-08-09 10:57:16.155", + "progress": 0, + "config": { + "editorSetting": { + "language": "r", + "editOnDblClick": false, + "completionSupport": true + }, + "colWidth": 12.0, + "editorMode": "ace/mode/r", + "fontSize": 9.0, + "results": {}, + "enabled": true, + "title": true + }, + "settings": { + "params": {}, + "forms": {} + }, + "results": { + "code": "SUCCESS", + "msg": [ + { + "type": "IMG", + "data": "iVBORw0KGgoAAAANSUhEUgAAA0gAAANICAMAAADKOT/pAAADAFBMVEUAAAABAQECAgIDAwME\nBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUW\nFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJyco\nKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6\nOjo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tM\nTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1e\nXl5fX19gYGBhYWFiYmJjY2NkZGRlZWVmZ [...] + } + ] + }, + "apps": [], + "runtimeInfos": {}, + "progressUpdateIntervalMs": 500, + "jobName": "paragraph_1624114803899_1367546113", + "id": "paragraph_1624114803899_1367546113", + "dateCreated": "2021-06-19 23:00:03.899", + "dateStarted": "2021-08-09 10:57:16.158", + "dateFinished": "2021-08-09 10:57:47.946", + "status": "FINISHED" + }, + { + "title": "Use ggplot2", + "text": "%r.ir\n\nlibrary(ggplot2)\npres_rating <- data.frame(\n rating = as.numeric(presidents),\n year = as.numeric(floor(time(presidents))),\n quarter = as.numeric(cycle(presidents))\n)\np <- ggplot(pres_rating, aes(x=year, y=quarter, fill=rating))\np + geom_raster()\n", + "user": "anonymous", + "dateUpdated": "2021-08-09 10:57:47.983", + "progress": 0, + "config": { + "editorSetting": { + "language": "r", + "editOnDblClick": false, + "completionKey": "TAB", + "completionSupport": true + }, + "colWidth": 6.0, + "editorMode": "ace/mode/r", + "fontSize": 9.0, + "title": true, + "results": {}, + "enabled": true + }, + "settings": { + "params": {}, + "forms": {} + }, + "results": { + "code": "SUCCESS", + "msg": [ + { + "type": "TEXT", + "data": "\nAttaching package: ‘ggplot2’\n\n\nThe following object is masked from ‘package:SparkR’:\n\n expr\n\n\n\n" + }, + { + "type": "IMG", + "data": "iVBORw0KGgoAAAANSUhEUgAAA0gAAANICAIAAAByhViMAAAACXBIWXMAABJ0AAASdAHeZh94\nAAAgAElEQVR4nO3deXxU5aH4/zMhqyFssuMGFSwouNSrFNGXerEuxaK+kBYXFK+CVmu9gq2A\n3wIutL1cEau2Ki5U0VIVitQFb6l1o1irgtBbLQjWiqCoSGQL2eb3x9xfGsGGmMnJJM+836/8\nkZk5zznPhDH5eM6cOYlkMhkBANDy5WR6AgAANA5hBwAQCGEHABAIYQcAEAhhBwAQCGEHABAI\nYQcAEAhhBwAQiNxMT+BztmzZUllZmZFN5+fnJxKJnTt3ZmTrLVdBQUFhYeH27dsrKioyPZcW\npqioqKKiIlMv+JarqKgoPz9/y5Yt1dXVmZ5LC1NcXLxjxw4/ty+rdevWrVq1Ki0tzfREWp6S\nkpItW7Y0eHj79u0bcTLZo3mFXXV1dVVVV [...] + } + ] + }, + "apps": [], + "runtimeInfos": {}, + "progressUpdateIntervalMs": 500, + "jobName": "paragraph_1624111096911_1421779245", + "id": "paragraph_1623916874799_812799753", + "dateCreated": "2021-06-19 21:58:16.911", + "dateStarted": "2021-08-09 10:57:47.986", + "dateFinished": "2021-08-09 10:57:48.701", + "status": "FINISHED" + }, + { + "title": "Use googleVis", + "text": "%r.ir\n\nlibrary(googleVis)\ndf=data.frame(country=c(\"US\", \"GB\", \"BR\"), \n val1=c(10,13,14), \n val2=c(23,12,32))\nBar <- gvisBarChart(df)\nprint(Bar, tag = 'chart')\n", + "user": "anonymous", + "dateUpdated": "2021-08-09 10:57:48.786", + "progress": 0, + "config": { + "editorSetting": { + "language": "r", + "editOnDblClick": false, + "completionKey": "TAB", + "completionSupport": true + }, + "colWidth": 6.0, + "editorMode": "ace/mode/r", + "fontSize": 9.0, + "title": true, + "results": {}, + "enabled": true + }, + "settings": { + "params": {}, + "forms": {} + }, + "results": { + "code": "SUCCESS", + "msg": [ + { + "type": "TEXT", + "data": "\nWelcome to googleVis version 0.6.10\n\nPlease read Google's Terms of Use\nbefore you start using the package:\nhttps://developers.google.com/terms/\n\nNote, the plot method of googleVis will by default use\nthe standard browser to display its output.\n\nSee the googleVis package vignettes for more details,\nor visit https://github.com/mages/googleVis.\n\nTo suppress this message use:\nsuppressPackageStartupMessages(library(googleVis))\n\n\n\n" + }, + { + "type": "HTML", + "data": "<!-- BarChart generated in R 3.6.3 by googleVis 0.6.10 package -->\n<!-- Mon Aug 9 10:57:48 2021 -->\n\n\n<!-- jsHeader -->\n<script type=\"text/javascript\">\n \n// jsData \nfunction gvisDataBarChartID32796be86efc () {\nvar data = new google.visualization.DataTable();\nvar datajson =\n[\n [\n\"US\",\n10,\n23\n],\n[\n\"GB\",\n13,\n12\n],\n[\n\"BR\",\n14,\n32\n] \n];\ndata.addColumn('string','country');\ndata.addColumn('number','val1');\ndata.addColumn('number','val2');\nd [...] + } + ] + }, + "apps": [], + "runtimeInfos": {}, + "progressUpdateIntervalMs": 500, + "jobName": "paragraph_1624111096911_1956298431", + "id": "paragraph_1616751026390_1945717741", + "dateCreated": "2021-06-19 21:58:16.911", + "dateStarted": "2021-08-09 10:57:48.789", + "dateFinished": "2021-08-09 10:57:48.851", + "status": "FINISHED" + }, + { + "text": "%r.ir\n", + "user": "anonymous", + "dateUpdated": "2021-08-09 10:57:48.889", + "progress": 0, + "config": { + "colWidth": 12.0, + "fontSize": 9.0, + "enabled": true, + "results": {}, + "editorSetting": { + "language": "r", + "editOnDblClick": false, + "completionSupport": true + }, + "editorMode": "ace/mode/r" + }, + "settings": { + "params": {}, + "forms": {} + }, + "results": { + "code": "SUCCESS", + "msg": [] + }, + "apps": [], + "runtimeInfos": {}, + "progressUpdateIntervalMs": 500, + "jobName": "paragraph_1624114845053_735333148", + "id": "paragraph_1624114845053_735333148", + "dateCreated": "2021-06-19 23:00:45.054", + "dateStarted": "2021-08-09 10:57:48.891", + "dateFinished": "2021-08-09 10:57:48.946", + "status": "FINISHED" + } + ], + "name": "3. R Conda Env in Yarn Mode", + "id": "2GB9HRSH9", + "defaultInterpreterGroup": "r", + "version": "0.10.0-SNAPSHOT", + "noteParams": {}, + "noteForms": {}, + "angularObjects": {}, + "config": { + "personalizedMode": "false", + "looknfeel": "default", + "isZeppelinNotebookCronEnable": false + }, + "info": { + "isRunning": true + } +} \ No newline at end of file diff --git a/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java b/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java index ef79fd5..56d0673 100644 --- a/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java +++ b/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java @@ -38,6 +38,7 @@ import java.io.InputStream; import java.io.StringReader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.util.Map; import java.util.Properties; /** @@ -153,6 +154,20 @@ public class IRInterpreter extends JupyterKernelInterpreter { } @Override + protected Map<String, String> setupKernelEnv() throws IOException { + Map<String, String> envs = super.setupKernelEnv(); + String pathEnv = envs.getOrDefault("PATH", ""); + if (condaEnv != null) { + // add ${PWD}/${condaEnv}/bin to PATH, otherwise JupyterKernelInterpreter will fail to + // find R to launch IRKernel + pathEnv = new File(".").getAbsolutePath() + File.separator + condaEnv + + File.separator + "bin" + File.pathSeparator + pathEnv; + envs.put("PATH", pathEnv); + } + return envs; + } + + @Override public String getKernelName() { return "ir"; }