12-04 06:39
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[Data Mining with R] Shiny Apps / Plot Output 본문

Data Science/Data Mining with R Programming

[Data Mining with R] Shiny Apps / Plot Output

cinema4dr12 2014. 10. 26. 21:46

[ui.R]

library(shiny); shinyUI(fluidPage( titlePanel("Plot Output Example - by cinema4dr12"), sidebarLayout( sidebarPanel( selectInput("var1", label = "Choose first variable", choices = c("mpg", "cyl", "disp", "hp", "drat", "wt", "qsec", "vs", "am", "gear", "carb"), selected = "mpg" ), selectInput("var2", label = "Choose second variable", choices = c("mpg", "cyl", "disp", "hp", "drat", "wt", "qsec", "vs", "am", "gear", "carb"), selected = "mpg" ) ), mainPanel( plotOutput("myPlot") ) ) ))


[server.R]

library(shiny); shinyServer( function(input, output){ output$myPlot = renderPlot({ x = input$var1; y = input$var2; switch(x, "mpg" = { dataX = mtcars$mpg; xlabel = "mpg"; }, "cyl" = { dataX = mtcars$cyl; xlabel = "cyl"; }, "disp" = { dataX = mtcars$disp; xlabel = "disp"; }, "hp" = { dataX = mtcars$hp; xlabel = "hp"; }, "drat" = { dataX = mtcars$drat; xlabel = "drat"; }, "wt" = { dataX = mtcars$wt; xlabel = "wt"; }, "qsec" = { dataX = mtcars$qsec; xlabel = "qsec"; }, "vs" = { dataX = mtcars$vs; xlabel = "vs"; }, "am" = { dataX = mtcars$am; xlabel = "am"; }, "gear" = { dataX = mtcars$gear; xlabel = "gear"; }, "carb" = { dataX = mtcars$carb; xlabel = "carb"; } ); switch(y, "mpg" = { dataY = mtcars$mpg; ylabel = "mpg"; }, "cyl" = { dataY = mtcars$cyl; ylabel = "cyl"; }, "disp" = { dataY = mtcars$disp; ylabel = "disp"; }, "hp" = { dataY = mtcars$hp; ylabel = "hp"; }, "drat" = { dataY = mtcars$drat; ylabel = "drat"; }, "wt" = { dataY = mtcars$wt; ylabel = "wt"; }, "qsec" = { dataY = mtcars$qsec; ylabel = "qsec"; }, "vs" = { dataY = mtcars$vs; ylabel = "vs"; }, "am" = { dataY = mtcars$am; ylabel = "am"; }, "gear" = { dataY = mtcars$gear; ylabel = "gear"; }, "carb" = { dataY = mtcars$carb; ylabel = "carb"; } ); main = paste("Plot between", xlabel); main = paste(main, " & "); main = paste(main, ylabel); plot(dataX, dataY, main = main, xlab = xlabel, ylab = ylabel); }) } )


[Results]

Comments