Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- library(rCharts)
- options(RCHART_WIDTH = 600)
- names(iris) = gsub('\\.', '', names(iris))
- app = shinyApp(
- ui = shinyUI(pageWithSidebar(
- headerPanel("iris data for bootstrap rcharts layout test"),
- sidebarPanel(
- selectInput("sp",label="choose iris species",
- choices=c("all","setosa","versicolor","virginica"))
- ),
- mainPanel(tabsetPanel(title="",
- tabPanel("Data Table",dataTableOutput("table")),
- tabPanel("Scatter Plots",
- showOutput("scatter1", "highcharts"),
- showOutput("scatter2", "polycharts"),
- showOutput("scatter3", "nvd3"))
- )))
- ), server = shinyServer(function(input, output) {
- vals = reactiveValues()
- vals$df = iris
- irisSpecies = observe({
- input$sp
- isolate({
- if (input$sp != "all")
- vals$df = subset(iris, iris$Species==input$sp)
- else
- vals$df = iris
- })
- })
- output$table <- renderDataTable({vals$df})
- output$scatter1 = renderChart({
- s1 <- hPlot(x = "PetalLength", y = "PetalWidth", data = vals$df, type = "scatter")
- s1$addParams(height = 400, dom = 'scatter1')
- return(s1)
- })
- output$scatter2 = renderChart({
- s2 <- rPlot(PetalWidth ~ PetalLength, data = vals$df, type = "point")
- xlim = range(vals$df$PetalLength)
- ylim = range(vals$df$PetalWidth)
- xlim = xlim + diff(xlim)/10 * c(-1,1)
- ylim = ylim + diff(ylim)/10 * c(-1,1)
- s2$addParams(height = 400, dom = 'scatter2')
- s2$guides(x = list(min = xlim[1], max = xlim[2]),
- y = list(min = ylim[1], max = ylim[2]))
- return(s2)
- })
- output$scatter3 = renderChart({
- s3 <- nPlot(PetalWidth ~ PetalLength, data = vals$df, type = "scatterChart")
- s3$addParams(height = 400, dom = 'scatter3')
- return(s3)
- })
- }))
- runApp(app)
Advertisement
Add Comment
Please, Sign In to add comment