library(shiny)
## Warning: package 'shiny' was built under R version 4.2.3
library(shinydashboard)
## 
## Attaching package: 'shinydashboard'
## The following object is masked from 'package:graphics':
## 
##     box
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.3
## 
## 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
library(readr)
## Warning: package 'readr' was built under R version 4.2.3
data <- read_csv("D:/hcv.csv")
## New names:
## • `` -> `...1`
## Rows: 615 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (2): Category, Sex
## dbl (12): ...1, Age, ALB, ALP, ALT, AST, BIL, CHE, CHOL, CREA, GGT, PROT
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#View(data)
ui <- dashboardPage(
  dashboardHeader(title = "HCV DATASET 20BDS0068",titleWidth = 400),
  dashboardSidebar(
    selectInput("Age", "Choose a age:", choices = unique(data$Age),
                multiple = TRUE, selected =
                  "32"),
    checkboxGroupInput("Category", "Choose a Blood Group:", choices =
                         c(unique(data$Category)),selected = "1=Hepatitis"),
    sliderInput("AST", "Select AST Range:", min =
                  min(data$AST), max =
                  max(data$AST), value = c(10.6,324)),
    actionButton("clear_button", "Clear Selection")
  ),
  dashboardBody(
    fluidRow(
      box(plotOutput("plot1", height = 250)),
      box(plotOutput("plot2", height = 250)),
      box(plotOutput("plot3", height = 250)),
      box(plotOutput("plot4", height = 250))
      
    )
  )
)
server <- function(input, output,session) {
  filter_data <- reactive({
    data %>% filter(AST >= input$AST[1] & AST <=
                      input$AST[2]) %>%
      filter(Category %in% input$Category) %>%
      filter(Age %in% input$Age)
  })
  output$plot1 <- renderPlot({
    ggplot(filter_data(), aes(
      x = Age,
      y = AST,
      color = as.factor(Category)))+
      geom_point() + labs(x = "Age", y = "AST")
  })
  output$plot2 <- renderPlot({
    ggplot(filter_data(), aes(
      x = Age, fill = as.factor(Age)))+
      geom_bar() + facet_wrap(~Category) +
      scale_x_log10()
  })
  output$plot3 <- renderPlot({
    ggplot(filter_data(), aes(
      x = Age, y = AST,
      color = as.factor(Category)))+
      geom_boxplot()
  })
  output$plot4 <- renderPlot({
    ggplot(filter_data(), aes(
      x = AST))+
      geom_density(fill = "green")+scale_x_log10()
  })
  observeEvent(input$clear_button, {
    updateSelectInput(session, "Age", selected = "32")
    updateRadioButtons(session, "Category", selected = "1=Hepatitis")
    updateSliderInput(session, "AST", value = c(10.6,324))
  })
}
shinyApp(ui, server)
Shiny applications not supported in static R Markdown documents