{% include JB/setup %}
R 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).
yum install R R-devel libcurl-devel openssl-devel
apt-get install r-base
Validate your installation with a simple R command:
R -e "print(1+1)"
To enjoy plots, install additional libraries with:
devtools with
R -e "install.packages('devtools', repos = 'http://cran.us.r-project.org')"
knitr with
R -e "install.packages('knitr', repos = 'http://cran.us.r-project.org')"
ggplot2 with
R -e "install.packages('ggplot2', repos = 'http://cran.us.r-project.org')"
Other visualization libraries:
R -e "install.packages(c('devtools','mplot', 'googleVis'), repos = 'http://cran.us.r-project.org'); require(devtools); install_github('ramnathv/rCharts')"
We recommend you to also install the following optional R libraries for happy data analytics:
Zeppelin supports R language in 3 interpreters
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.
%r.r
& %r.ir
)By default, the R Interpreter appears as two Zeppelin Interpreters, %r.r
and %r.ir
.
%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.
R basic expression
R base plotting is fully supported
Besides R base plotting, you can use other visualization library, e.g. ggplot
and googlevis
Shiny 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(type=server) # Define server logic to summarize and view selected dataset ---- server <- function(input, output) { # Return the requested dataset ---- datasetInput <- reactive({ switch(input$dataset, "rock" = rock, "pressure" = pressure, "cars" = cars) }) # Generate a summary of the dataset ---- output$summary <- renderPrint({ dataset <- datasetInput() summary(dataset) }) # Show the first "n" observations ---- output$view <- renderTable({ head(datasetInput(), n = input$obs) }) }
%r.shiny(type=ui) # Define UI for dataset viewer app ---- ui <- fluidPage( # App title ---- titlePanel("Shiny Text"), # Sidebar layout with a input and output definitions ---- sidebarLayout( # Sidebar panel for inputs ---- sidebarPanel( # Input: Selector for choosing dataset ---- selectInput(inputId = "dataset", label = "Choose a dataset:", choices = c("rock", "pressure", "cars")), # Input: Numeric entry for number of obs to view ---- numericInput(inputId = "obs", label = "Number of observations to view:", value = 10) ), # Main panel for displaying outputs ---- mainPanel( # Output: Verbatim text for data summary ---- verbatimTextOutput("summary"), # Output: HTML table with requested number of observations ---- tableOutput("view") ) ) )
%r.shiny(type=run)
After executing the run type R shiny paragraph, the shiny app will be launched and embedded as Iframe in paragraph.
If you want to run multiple shiny app, you can specify app
in paragraph local property to differentiate shiny app.
e.g.
%r.shiny(type=ui, app=app_1)
%r.shiny(type=server, app=app_1)
%r.shiny(type=run, app=app_1)