celestialgod

shiny rCharts

Jul 26th, 2015
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.45 KB | None | 0 0
  1. library(shiny)
  2. library(rCharts)
  3. app = shinyApp(
  4.   ui = shinyUI(fluidPage(
  5.    titlePanel("iris data for bootstrap rcharts layout test"),
  6.    sidebarLayout
  7.    (
  8.       sidebarPanel
  9.       (
  10.       selectInput("sp",label="choose iris species",choices=c("all","setosa","versicolor","virginica"))
  11.       ),
  12.    
  13.       mainPanel
  14.       (
  15.       navbarPage(
  16.          title="",
  17.          tabPanel("iris_raw",dataTableOutput("table")),
  18.          tabPanel("scatter_plot",showOutput("scatter","Highcharts"),showOutput("scatter2","Highcharts")
  19.          ))
  20.       )
  21.    )
  22.   )
  23. ),
  24.   server =  shinyServer(function(input, output) {
  25.    output$table <- renderDataTable({
  26.       iris.new=iris
  27.       if(input$sp!="all") {iris.new=iris[which(iris$Species==input$sp),]}
  28.       iris.new
  29.    })
  30.    
  31.    output$scatter=renderChart( #draw relationship between Sepal.Length & Sepal.Width
  32.       {
  33.          iris.new=iris
  34.          if(input$sp!="all") {iris.new=iris[which(iris$Species==input$sp),]}
  35.          a <- hPlot(x="Petal.Length",y="Petal.Width",data = iris.new,type = "scatter")
  36.          a
  37.  
  38.       }
  39.    )
  40.    output$scatter=renderChart( #draw relationship between Petal.Length & Petal.Width
  41.       {
  42.          iris.new=iris
  43.          if(input$sp!="all") {iris.new=iris[which(iris$Species==input$sp),]}
  44.          a <- rPlot(x="Petal.Length",y="Petal.Width",data = iris.new[which(iris.new$Species==input$sp),],type = "point")
  45.          a
  46.       }
  47.    )
  48.       }
  49.    )
  50. )
  51. runApp(app)
Advertisement
Add Comment
Please, Sign In to add comment