Skip to content

Instantly share code, notes, and snippets.

@johndharrison
Created October 21, 2013 22:30
Show Gist options
  • Save johndharrison/7092047 to your computer and use it in GitHub Desktop.
Save johndharrison/7092047 to your computer and use it in GitHub Desktop.
R Shiny regression example
library(RJSONIO)
shinyServer(function(input, output, session) {
output$test <- renderUI({
noPoints <- as.integer(input$obs)
series <- toJSON(cbind(seq(88, 266, by = (266-88)%/%(noPoints-1)), 113))
tags$script(HTML(
paste0("$(document).ready(function () {
$.jqplot.config.enablePlugins = true;
s1 = ",
series,
";
plot1 = $.jqplot('chart2',[s1],{
title: 'Highlighting, Dragging, Cursor and Trend Line',
seriesDefaults: {
showLine: false
},
axes: {
xaxis: {
labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
label: \"X Axis\"
},
yaxis: {
tickOptions: {
labelRenderer: $.jqplot.CanvasAxisLabelRenderer
},
label: \"Y Axis\",
max: 200,
min: 0
}
},
highlighter: {
sizeAdjust: 10,
tooltipLocation: 'n',
tooltipAxes: 'xy',
useAxesFormatters: false
},
cursor: {
show: true
}
});
});")
))
})
})
# Define UI
shinyUI(
pageWithSidebar(
# Application title
headerPanel("Hello Shiny!"),
# Sidebar with a slider input
sidebarPanel(
sliderInput("obs",
"Number of observations:",
min = 2,
max = 9,
value = 5)
),
# Show a plot of the generated distribution
mainPanel(
tags$head(
includeScript("www/dist/jquery.jqplot.min.js"),
includeScript("www/dist/plugins/jqplot.dateAxisRenderer.min.js"),
includeScript("www/dist/plugins/jqplot.barRenderer.min.js"),
includeScript("www/dist/plugins/jqplot.categoryAxisRenderer.min.js"),
includeScript("www/dist/plugins/jqplot.cursor.min.js"),
includeScript("www/dist/plugins/jqplot.highlighter.min.js"),
includeScript("www/dist/plugins/jqplot.dragable.min.js"),
includeScript("www/dist/plugins/jqplot.trendline.min.js"),
includeCSS("www/dist/jquery.jqplot.min.css"),
uiOutput('test')
),
tags$div(id = 'chart2')
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment