library(shiny)
## Warning: package 'shiny' was built under R version 4.2.2
library(shinydashboard)
## Warning: package 'shinydashboard' was built under R version 4.2.2
##
## Attaching package: 'shinydashboard'
## The following object is masked from 'package:graphics':
##
## box
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.2
# Load the data
data <- read.csv("https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/wdbc.data", header = FALSE)
# Preprocess the data
data <- data[-1]
data$V2 <- as.factor(data$V2)
# Define the UI
ui <- dashboardPage(
dashboardHeader(title = "Breast Cancer Wisconsin 20BDS0177"),
dashboardSidebar(
selectInput("variable1", "Select variable 1", names(data)[-1]),
selectInput("variable2", "Select variable 2", names(data)[-1])
),
dashboardBody(
fluidRow(
box(
plotOutput("scatterplot"),
width = 6
),
box(
plotOutput("boxplot"),
width = 6
)
),
fluidRow(
box(
plotOutput("histogram"),
width = 6
),
box(
plotOutput("densityplot"),
width = 6
)
),
fluidRow(
box(
tableOutput("summary"),
width = 12
)
),
fluidRow(
box(
downloadButton("downloadData", "Download Data"),
width = 12
)
)
)
)
# Define the server
server <- function(input, output) {
# Create the scatterplot
output$scatterplot <- renderPlot({
ggplot(data, aes_string(x = input$variable1, y = input$variable2, color = "V2")) +
geom_point()
})
# Create the boxplot
output$boxplot <- renderPlot({
ggplot(data, aes_string(x = "V2", y = input$variable1)) +
geom_boxplot()
})
# Create the histogram
output$histogram <- renderPlot({
ggplot(data, aes_string(x = input$variable1, fill = "V2")) +
geom_histogram(alpha = 0.5, position = "identity", bins = 30)
})
# Create the densityplot
output$densityplot <- renderPlot({
ggplot(data, aes_string(x = input$variable1, fill = "V2")) +
geom_density(alpha = 0.5) +
labs(title = paste("Density plot of", input$variable1))
})
# Create the summary table
output$summary <- renderTable({
summary(data)
})
# Download the data
output$downloadData <- downloadHandler(
filename = function() {
paste("breast-cancer-wisconsin-", Sys.Date(), ".csv", sep = "")
},
content = function(file) {
write.csv(data, file)
}
)
}
# Run the app
shinyApp(ui, server)
Shiny applications not supported in static R Markdown documents