-
-
Save ramnathv/ba423fe2cab9a1518e3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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