To work with R, you’ll need to load the IRKernel and activate it to get started on working with R in the notebook environment.
First, you'll need to install some packages. Make sure that you don't do this in your RStudio console, but in a regular R terminal:
$ R
> install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
This command will prompt you to type in a number to select a CRAN mirror to install the necessary packages. Enter a number and the installation will continue.
> devtools::install_github('IRkernel/IRkernel')
If above command doesnt work then you may try it in RStudio. Then, you still need to make the R kernel visible for Jupyter:
# Install IRKernel for the current user
> IRkernel::installspec()
# Or install IRKernel system-wide
> IRkernel::installspec(user = FALSE)
One other thing to do before we open jupyter is to go to location :
C:\Users\tparmar\AppData\Roaming\jupyter\kernels\ir
Now open kernel.json
to modify the path to "C:/Program Files/R/R-3.3.1/bin/x64/R"
Please make sure your default R package Library folder is on C drive as show above..
We are done, open up the notebook application with jupyter notebook
. You'll see R appearing in the list of kernels when you create a new notebook.
You may also checkout Plotly R site to see more examples Plotly Charts In Jupyter Notebooks Using R
getwd()
.libPaths()
library(ggplot2)
library(plotly)
knitr::opts_chunk$set(echo = TRUE)
source("//fc8fss04/tparmar/Profile/Documents/R/myR/Yahoo Stock Data Pull.R")
MSFT <- GetYahooData("MSFT")
INTC <- GetYahooData("INTC")
IBM <- GetYahooData("IBM")
AAPL <- GetYahooData("AAPL")
mat <- data.frame(Date = MSFT$Date,
MSFT = round(MSFT$Adj.Close,2),
IBM = round(IBM$Adj.Close,2),
AAPL = round(AAPL$Adj.Close,2),
INTC = round(INTC$Adj.Close,2))
summary(mat)
library(plotly)
library(dplyr)
p <- plot_ly(mat, x = ~Date, y = ~MSFT, type = "scatter", mode = "lines", fill = "tozeroy", name = "Microsoft") %>%
add_trace(y = ~INTC, fill = "tonexty", name = "Intel") %>%
add_trace(y = ~AAPL, fill = "tonexty", name = "Apple") %>%
add_trace(y = ~IBM, fill = "tonexty", name = "IBM") %>%
layout(title = "Stock Prices",
xaxis = list(title = "Time"),
yaxis = list(title = "Stock Prices"))
p # Thats it !