I am trying to plot time series financial OHLC data as candlesticks from R using Highstock JS. I am using rcharts package. However, the plot takes significant amount of time to display ( around 5 mins for 10,000 candles.
I have also tried using ggplot2 to construct candles and for interactivity, have used plotly. Though ggplot2 renders the plot very quick, when I use plotly, it slows down.
I basically require tooltip and horizontol scrollbar in my graph.
I have added a sample code created using ggplot2 and shiny with scroll
ui.R
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel(NULL),
# Sidebar with a slider input for scrolling
sidebarLayout(
sidebarPanel(
sliderInput("integer", "Scroll parameter:",
min=51, max=2000, value=100)
),
mainPanel(
plotOutput("plot",
hover = hoverOpts(
id = "plot_hover")
)
)),
fluidRow(
column(width = 3,
verbatimTextOutput("hover_info")
)
)))
server.R
library(ggplot2)
library(shiny)
library(plotly)
shinyServer(function(input, output) {
set.seed(1)
s <- sample(seq(from = 1, to = 50, by = 1), size = 2000, replace = TRUE)
data <- data.frame(x = 1:length(s), y = s)
df <- reactive({
df <- data[(input$integer - 50):input$integer,] # selecting only 50 rows of data frame and generating the plot
return(df)
})
output$plot <- renderPlot({
temp <- df()
p <- ggplot(data = temp, mapping = aes(x=x,y=y))
p <- p+geom_line()
print(p)
# g <- ggplotly(p) # for conversion to plotly
# print(g)
})
output$hover_info <- renderPrint({
cat("input$plot_hover:\n")
str(input$plot_hover)
})
})
the problem in this is that every time I change the scroll parameter, the plot is recreated and so the processing time is slow.( around .3 secs). Also the scroll is not smooth when I move with mouse.
Is there any way I can load the whole of ggplot in high res and have scrollbar .
Also I require a tooltip, which is why I cannot load as image I guess.
I understand that for interactivity, processing time required is high. But is there any other way of doing this for rendering faster charts.
I am running on MAC OS with 8 GB RAM.