R Markdown
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)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
data = read.csv(file.choose(), header=T)
ui <- dashboardPage(
skin = "purple",
dashboardHeader(title = "Shiny Dashboard 20BDS0410",titleWidth = 400),
dashboardSidebar(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
selectInput("Degree", "Degree:", choices = c(unique(data$Degree)),
multiple = T, selected ="high"),
checkboxGroupInput("caprice", "Caprice:",
choices = c(unique(data$caprice)), selected = "left"),
actionButton("clear_button", "Clear Selection")
),
dashboardBody(
fluidRow(
box(title="Degree Count:", status = "warning", solidHeader = TRUE, plotOutput("plot1", height = 250)),
box(title="Topic Distribution:", status = "info", solidHeader = TRUE, plotOutput("plot2", height = 250)),
box(title="Published Topic:", status = "danger", solidHeader = TRUE, plotOutput("plot3", height = 250)),
box(title="Published Caprice:", status = "success", solidHeader = TRUE, plotOutput("plot4", height = 250))
)
)
)
server <- function(input, output,session) {
degree_data <- reactive({
data %>% filter(Degree %in% input$Degree) %>% filter(caprice %in% input$caprice)
})
output$plot1 <- renderPlot({
ggplot(degree_data(), aes(x = Degree, fill = as.factor(pb))) +
geom_bar()
})
output$plot2 <- renderPlot({
pie(table(factor(degree_data()$topic)), mar=rep(1,4),
col = hcl.colors(length(data), "Spectral"),
labels = table(factor(degree_data()$topic)),
explode = 0.1)
})
output$plot3 <- renderPlot({
ggplot(degree_data(), aes(x = topic)) +
geom_bar(
aes(fill = Degree), color = "white",
position = position_dodge(0.9)
)+
facet_wrap(~pb)
})
output$plot4 <- renderPlot({
ggplot(degree_data(), aes(x = pb, fill = caprice)) +
geom_bar(position = "fill") +
labs(y = "Proportion")
})
}
shinyApp(ui, server)
Shiny applications not supported in static R Markdown documents