Last active
June 2, 2016 09:51
-
-
Save mbannert/9124890 to your computer and use it in GitHub Desktop.
Demo Radar chart app from http://glimmer.rstudio.com/mbannert/radar_chart/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data_sets <- c("mtcars") | |
shinyServer(function(input, output) { | |
# Drop-down selection box for which data set | |
output$choose_dataset <- renderUI({ | |
selectInput("dataset", "Data set", as.list(data_sets)) | |
}) | |
# select a car | |
output$choose_car <- renderUI({ | |
selectInput("car","car",as.list(rownames(get(input$dataset)))) | |
}) | |
# Check boxes | |
output$choose_columns <- renderUI({ | |
# If missing input, return to avoid error later in function | |
if(is.null(input$dataset)) | |
return() | |
# Get the data set with the appropriate name | |
dat <- get(input$dataset) | |
colnames <- names(dat) | |
# Create the checkboxes and select them all by default | |
checkboxGroupInput("columns", "Choose columns", | |
choices = colnames, | |
selected = colnames) | |
}) | |
output$radar <- renderPlot({ | |
source("radar.R") | |
webplot(get(input$dataset), | |
which(rownames(mtcars) == input$car), y.cols = input$columns,add=F) | |
}) | |
# Output the data | |
output$data_table <- renderTable({ | |
# If missing input, return to avoid error later in function | |
if(is.null(input$dataset)) | |
return() | |
# Get the data set | |
dat <- get(input$dataset) | |
# Make sure columns are correct for data set (when data set changes, the | |
# columns will initially be for the previous data set) | |
if (is.null(input$columns) || !(input$columns %in% names(dat))) | |
return() | |
# Keep the selected columns | |
dat <- dat[, input$columns, drop = FALSE] | |
# Return first 20 rows | |
head(dat, 20) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shinyUI(pageWithSidebar( | |
headerPanel("Car Comparison Radar"), | |
sidebarPanel( | |
uiOutput("choose_dataset"), | |
uiOutput("choose_car"), | |
uiOutput("choose_columns"), | |
br(), | |
a(href = "http://statisticstoproveanything.blogspot.de/2013/11/spider-web-plots-in-r.html", | |
"Radar by Alan Vaughn from statisticstoproveanything"), | |
br(), | |
a(href = "https://gist.github.com/mbannert/9124890/", | |
"Find the shiny code gist here.") | |
), | |
mainPanel( | |
plotOutput(outputId = "radar", height = "600px"), | |
tableOutput("data_table") | |
) | |
)) |
hi, tts! I'm having the same problem you had at first. It throws me some errors:
Error in get(input$dataset) : invalid first argument
Warning in file(filename, "r", encoding = encoding) :
cannot open file 'radar.R': No such file or directory
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
Warning in file(filename, "r", encoding = encoding) :
cannot open file 'radar.R': No such file or directory
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
Would you give me a hint how you fixed this? Thanks!!
Okay, I got it. I just had to run together the webplot function available at: http://statisticstoproveanything.blogspot.de/2013/11/spider-web-plots-in-r.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, my mistake/misunderstanding. Errors were warnings, and the radar chart do pops up. Case closed, and thanks for sharing!