maandag 26 april 2021

Data Journalism on the Samsung Tablet with Termux, Ubuntu and R

Can I turn my Tablet into a real work station? Apps are nice for small jobs, reading mail and bit of browsing. But for work…Office is a nice app and gives you all the standard Office tools like Word and Excel, lite versions of course, but working OK. But how about doing statistics with R? No R for Android so you need Linux environment. Installing Linux in a box in Android is possible with for example Linux Deploy app. However you need to root the machine. Generally I have no problem with that: I want full control on all machines. Rooting a machine has a consequence: losing the warrant. An secondly is a working root for this specific machine with that Android version available. And finally you run the risk in case of failure to turn you machine in a brick.





Termux

No rooting at the moment, but there is a nice solution available using Termux. Termux is an Android terminal emulator and Linux environment application that works directly with no rooting or setup required. A minimal base system is installed automatically, additional packages are available using the package manager. More on Termux, read the wiki: https://wiki.termux.com/wiki/Main_Page .

How to do an install for R is finding an example or discussion on the web. Here is a nice one: https://stackoverflow.com/questions/36968411/installing-r-on-android . I used the second option; the ‘ browser (jupyter) approach’.



The browser (jupyter) approach

Termux

    • install termux (google play) (As termux didn't run jupyter-IRkernel, I had to install ubuntu)

    • install ubuntu in termux (MFDGaming or Neo-Oli).

Installation steps for MFDGaming 

    1. Update termux: apt-get update && apt-get upgrade -y

    2. Install wget: apt-get install wget -yfor MFD

    3. Install proot: apt-get install proot -y

    4. Install git: apt-get install git -y

    5. Go to HOME folder: cd ~

    6. Download script: git clone https://github.com/MFDGaming/ubuntu-in-termux.git

    7. Go to script folder: cd ubuntu-in-termux

    8. Give execution permission: chmod +x ubuntu.sh

    9. Run the script: ./ubuntu.sh -y

    10. Now just start ubuntu: ./startubuntu.sh


    • run this in ubuntu:

    apt update && apt upgrade

    apt-get install apt-transport-https software-properties-common


    # add R repository

    add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu disco-cran35/'

    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

    apt update && apt upgrade

    

    apt install nodejs

    apt install npm # absence of this causes non-editable cells in jupyter

    apt install gfortran

    apt install liblapack-dev

    apt install libopenblas-dev

    

    # install R

    apt install r-base-dev # or r-base or r-base-core

    

    # install python package manager

    apt-get install python3-pip


    # install jupyter

    pip3 install jupyterlab


    # open R

    R 

    • Inside R:

    # Package necessary for jupyter

    install.packages("IRkernel")

    IRkernel::installspec()

    q()

    • In ubuntu, run the jupyter lab

    jupyter lab --allow-root

    # as you will see you have to paste something like this in your internet browser

    http://127.0.0.1:8889/?token=1a0f9b3d472d155bb4d46df119b937646d6192f569c9d635 


Well it takes some time, but in the end it works. The S7 ready for some data journalism analysis in R.

I have Ubuntu running in terminal mode and use the command line to for jobs. And R running in terminal mode as well. More on R: https://www.r-project.org/ .The R console has a steap learning curve, however Rstudio needs root access. An alternative to this whole operation is to install a Rstudio server on an other machine and then login from the tablet.

This script goes one step further: it installs a Jupyter notebook to run R or Python code. More on Jupyter: https://jupyter.org/documentation .

Here are some screenshots: