Extra Credit Assignment
Extra Credit
Due November 13th
Please publish your web-application using Shinyapps.io, using the publish button on R Studio. You’ll needed to create a default account at http://www.shinyapps.io/.
Example dataset: https://github.com/davcraig75/midterm/raw/main/data.tar.gz
- Level 1: Build a Shiny.io App using Geiser demo (5 points)
- Level 2: Build a Shiny.io Data explorer from Part A below (+5 points)
- Level 3: Build a Shiny.io Data explorer Using Part B Below (+10 points)
- Level 4: Allow uploading of a dataset (+20 points) * hard
BUILDING A DATA EXPLORER
Part A: Starting Template
# The data library(ggplot2) library(shiny) library(RColorBrewer) dataset <- read.csv('~/trgn510/sample_info.csv',header = TRUE, sep = ",", quote = "\"", dec = ".", fill = TRUE, row.names = 1) headerNames=colnames(dataset) ui <- fluidPage( pageWithSidebar( headerPanel("Data Explorer"), sidebarPanel( selectInput('x', 'X', c("None"=FALSE,headerNames),headerNames[2]), selectInput('y', 'Y', c("None"=FALSE,headerNames),headerNames[3]), selectInput('fill', 'Fill', c("None"=FALSE,headerNames),headerNames[5]), checkboxInput('geom_point', 'geom_point',TRUE) ), mainPanel( plotOutput('plot') ) ) ) # Define server logic required to draw a histogram server <- function(input, output) { output$plot <- renderPlot({ p <- ggplot(dataset, aes_string( x=input$x, fill=input$fill)) if (input$geom_point) p <- p + geom_point(aes_string(y=input$y)) print(p) }, height=700) } # Run the application shinyApp(ui = ui, server = server)
Please make the necessary changes to get working within your development environment of R Studio
Please modify the code to add a size aesthetic (e.g. adding an option from select input, and an additional size aesthetic), such that it looks like below (link below uses a different dataset):
https://foundinpd.shinyapps.io/explorer/
Part B: Understanding Pivoting.
Please add inputs to allow us to facet or pivot the data. In the UI, add the following code:
selectInput('facet_row', 'Facet Row', c(None='.', headerNames)), selectInput('facet_col', 'Facet Column', c(None='.', headerNames)),
In the server add the following code before the print(p)
:
facets <- paste(input$facet_row, '~', input$facet_col) if (facets != '. ~ .') p <- p + facet_grid(facets)
You should have two new options, explore what pivoting does. Modify the code to only allow choices that are factors to the facet
Adding more types of graphs
Add dot plots by adding the following to the UI.
checkboxInput('geom_dotplot', 'geom_dotplot'), checkboxInput('geom_bar', 'geom_bar'),
and the following to the server
if (input$geom_bar) p <- p + geom_bar() # geom_dotplot doesn't requires an y input if (input$geom_dotplot) p <- p + geom_dotplot()
Modify code to add a violin option
Modify code to add a geom_violin option
Modify code to add a geom_histogram option
Modify code to add a geom_density_2d option
Modify code to add a geom_bin2d option
Add capabilities to do polar coordinates, and verify that it works.