Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Created July 17, 2013 23:27
Show Gist options
  • Save ramnathv/ba423fe2cab9a1518e3d to your computer and use it in GitHub Desktop.
Save ramnathv/ba423fe2cab9a1518e3d to your computer and use it in GitHub Desktop.
.chart_container {
position: relative;
display: inline-block;
font-family: Arial, Helvetica, sans-serif;
}
.rChart {
display: inline-block;
margin-left: 40px;
}
.yAxis {
position: absolute;
top: 0;
bottom: 0;
width: 40px;
}
.legend {
position: absolute;
top: 0;
right: -160px;
vertical-align: top;
}
.slider {
margin-left: 40px;
margin-top: 12px;
}
## server.R
library(shiny)
library(rCharts)
library(rattle)
data(weather)
w = weather
dateToSeconds = function (date) {
date = as.POSIXct(as.Date(date), origin = "1970-01-01")
as.numeric(date)
}
# Modified version of renderChart
renderChart2 <- function(expr, env = parent.frame(), quoted = FALSE) {
func <- shiny::exprToFunction(expr, env, quoted)
function() {
rChart_ <- func()
cht_style <- sprintf("<style>.rChart {width: %spx; height: %spx} </style>",
rChart_$params$width, rChart_$params$height)
cht <- paste(capture.output(rChart_$print()), collapse = '\n')
HTML(paste(c(cht_style, cht), collapse = '\n'))
}
}
w$Date = dateToSeconds(w$Date)
shinyServer(function(input, output) {
output$plot = renderChart2({
rs = Rickshaw$new()
rs$layer(MinTemp ~ Date, data = w, type = "line")
rs$set(width = 600)
return(rs)
})
})
### ui
# moved from lower down so call to `showOutput` would not fail
library(rCharts)
library(rattle)
shinyUI(
pageWithSidebar(
headerPanel("Rickshaw test"),
sidebarPanel(
selectInput("variable",
"Choice is arbitrary:",
c("Choice 1", "Choice 2")
)
),
mainPanel(
div(id = 'myplot',
includeCSS("rickshaw.css"),
showOutput("plot", "Rickshaw")
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment