Advertisement
swchen

rCharts in shiny

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