Load necessary libraries

library(shiny) library(ggplot2) library(dplyr) library(tidyr)

setwd(“C:/Users/Deepu Dangwal/Desktop/Chandra”)

Load and prepare dataset

bank_data <- read.csv(“AUS_bank_data.csv”)

Check if the data loaded correctly

print(“Data loaded successfully”) print(head(bank_data))

Ensure state and Desired_Target columns are treated as factors for categorical analysis

bank_data\(state <- as.factor(bank_data\)state) bank_data\(Desired_Target <- as.factor(bank_data\)Desired_Target)

Filter for reasonable values (e.g., focus on Contacts_during_the_Campaign > 0)

bank_data_filtered <- bank_data %>% filter(Contacts_during_the_Campaign > 0)

Define UI

ui <- fluidPage( titlePanel(“Australian Banking Campaign Analysis Dashboard”),

sidebarLayout( sidebarPanel( selectInput(“state_select”, “Select State for Analysis:”, choices = unique(bank_data_filtered$state), selected = “New South Wales”, # Set a single default state multiple = TRUE) ),

mainPanel(
  tabsetPanel(
    tabPanel("Subscription Target Analysis", plotOutput("target_plot")),  
    tabPanel("Average Contacts by State", plotOutput("avg_contacts_plot")),  
    tabPanel("Campaign Contacts Distribution", plotOutput("boxplot_plot"))  
  )
)

) )

Define Server Logic

server <- function(input, output) {

# Reactive Data for Selected States trend_data <- reactive({ selected_data <- bank_data_filtered %>% filter(state %in% input$state_select)

# Debug: Check if trend_data() is filtered correctly
print("Selected trend data:")
print(head(selected_data))

selected_data

})

# Subscription Target Analysis Plot output$target_plot <- renderPlot({ req(trend_data()) # Ensure data exists before plotting ggplot(trend_data(), aes(x = Desired_Target, fill = Desired_Target)) + geom_bar() + labs(title = “Subscription Target Outcome Analysis”, x = “Desired Target”, y = “Count”) + theme_minimal() })

# Average Contacts by State Plot output$avg_contacts_plot <- renderPlot({ avg_contacts_state <- bank_data_filtered %>% group_by(state) %>% summarise(Average_Contacts = mean(Contacts_during_the_Campaign, na.rm = TRUE)) %>% arrange(desc(Average_Contacts))

ggplot(avg_contacts_state, aes(x = reorder(state, -Average_Contacts), y = Average_Contacts)) +
  geom_bar(stat = "identity", fill = "skyblue") +
  coord_flip() +
  labs(title = "Average Contacts by State",
       x = "State",
       y = "Average Contacts During Campaign") +
  theme_minimal()

})

# Campaign Contacts Distribution (Boxplot) output$boxplot_plot <- renderPlot({ req(bank_data_filtered) # Ensure data exists before plotting ggplot(bank_data_filtered, aes(x = as.factor(state), y = Contacts_during_the_Campaign)) + geom_boxplot(outlier.color = “red”, fill = “lightblue”) + labs(title = “Distribution of Contacts During Campaign by State”, x = “State”, y = “Contacts During Campaign”) + theme(axis.text.x = element_text(angle = 90, hjust = 1)) }) }

Run the application

shinyApp(ui = ui, server = server)