Browse Source

Data upload, download, display, modals and modules added.

main
Asitav Sen 4 years ago
parent
commit
a8a6d43d67
  1. 4
      .Rproj.user/178A6739/sources/prop/48F98022
  2. 4
      .Rproj.user/178A6739/sources/prop/A1AE5A83
  3. 10
      .Rproj.user/178A6739/sources/session-99529da2/58AD392C
  4. 126
      .Rproj.user/178A6739/sources/session-99529da2/58AD392C-contents
  5. 8
      .Rproj.user/178A6739/sources/session-99529da2/FE6BB309
  6. 5
      .Rproj.user/178A6739/sources/session-99529da2/FE6BB309-contents
  7. 24
      .Rproj.user/178A6739/sources/session-99529da2/FEF97A26
  8. 141
      .Rproj.user/178A6739/sources/session-99529da2/FEF97A26-contents
  9. 5
      app.R
  10. 141
      mod_basic.R
  11. 104
      modals.R
  12. 126
      panel.R

4
.Rproj.user/178A6739/sources/prop/48F98022

@ -1,6 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "50,5",
"scrollLine": "25"
"cursorPosition": "50,4",
"scrollLine": "12"
}

4
.Rproj.user/178A6739/sources/prop/A1AE5A83

@ -1,6 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "36,2",
"scrollLine": "0"
"cursorPosition": "140,7",
"scrollLine": "121"
}

10
.Rproj.user/178A6739/sources/session-99529da2/58AD392C

@ -3,7 +3,7 @@
"path": "~/Projects/LoanRisk/panel.R",
"project_path": "panel.R",
"type": "r_source",
"hash": "814836357",
"hash": "2913767970",
"contents": "",
"dirty": false,
"created": 1686047069391.0,
@ -12,15 +12,15 @@
"properties": {
"source_window_id": "",
"Source": "Source",
"cursorPosition": "50,5",
"scrollLine": "25"
"cursorPosition": "50,4",
"scrollLine": "12"
},
"folds": "",
"lastKnownWriteTime": 1686047216,
"lastKnownWriteTime": 1686047587,
"encoding": "UTF-8",
"collab_server": "",
"source_window": "",
"last_content_update": 1686047216552,
"last_content_update": 1686047587539,
"read_only": false,
"read_only_alternatives": []
}

126
.Rproj.user/178A6739/sources/session-99529da2/58AD392C-contents

@ -48,67 +48,67 @@ panel1<-
")
)
),
))#,
# tags$hr(),
# fluidRow(
# column(
# width = 6,
# fluidRow(
# h3("Data"),
# br(),
# p("This section shows the data (uploaded or inbuilt sample).")
# ),
# br(),
# withSpinner(dataTableOutput("up_data"),type = 7,
# color = "black"),
# br(),
# actionButton("uploadnew", "Upload New Data", class="btn-light")
# ),
# column(width = 6,
# br(),
# basicstatUI("nofloans"))
#
# ),
# br(),
# br(),
# fluidRow(
# column(
# width = 6,
# h3("With Macroeconomic data"),
# p(
# "In this section, we add macroeconomic data. Please select the country of the asset and click on fetch button. If download fails, click again or try after sometime. Please note that GDP data has been discontinued by IMF recently. Hence, using Industrial output temporarily."
# ),
# column(
# width = 6,
# selectInput(
# "country",
# "Country",
# selected = "India",
# choices = countries$Country
# )
# ),
# column(
# width = 6,
# br(),
# actionButton("fetchimf", "Fetch IMF data", class = "glow")
# ),
# withSpinner(
# dataTableOutput("fulldata"),
# type = 7,
# color = "black"
# )
# ),
# column(width = 6,
# uiOutput("ac_button"),
# uiOutput("expcalcu"))
# ),
# br(),
# br(),
# fluidRow(column(width = 11,
# uiOutput("scenario_opts"))),
# br(),
# fluidRow(column(width = 11,
# uiOutput("credit_loss"))),
# fluidRow(column(width = 11,
# uiOutput("dlmanager")))
)),
tags$hr(),
fluidRow(
column(
width = 6,
fluidRow(
h3("Data"),
br(),
p("This section shows the data (uploaded or inbuilt sample).")
),
br(),
withSpinner(dataTableOutput("up_data"),type = 7,
color = "black"),
br(),
actionButton("uploadnew", "Upload New Data", class="btn-light")
),
column(width = 6,
br(),
basicstatUI("nofloans"))
),
br(),
br(),
fluidRow(
column(
width = 6,
h3("With Macroeconomic data"),
p(
"In this section, we add macroeconomic data. Please select the country of the asset and click on fetch button. If download fails, click again or try after sometime. Please note that GDP data has been discontinued by IMF recently. Hence, using Industrial output temporarily."
),
column(
width = 6,
selectInput(
"country",
"Country",
selected = "India",
choices = countries$Country
)
),
column(
width = 6,
br(),
actionButton("fetchimf", "Fetch IMF data", class = "glow")
),
withSpinner(
dataTableOutput("fulldata"),
type = 7,
color = "black"
)
),
column(width = 6,
uiOutput("ac_button"),
uiOutput("expcalcu"))
),
br(),
br(),
fluidRow(column(width = 11,
uiOutput("scenario_opts"))),
br(),
fluidRow(column(width = 11,
uiOutput("credit_loss"))),
fluidRow(column(width = 11,
uiOutput("dlmanager")))
)

8
.Rproj.user/178A6739/sources/session-99529da2/FE6BB309

@ -12,15 +12,15 @@
"properties": {
"source_window_id": "",
"Source": "Source",
"cursorPosition": "36,2",
"scrollLine": "0"
"cursorPosition": "140,7",
"scrollLine": "121"
},
"folds": "",
"lastKnownWriteTime": 1686047140,
"lastKnownWriteTime": 1686049083,
"encoding": "UTF-8",
"collab_server": "",
"source_window": "",
"last_content_update": 1686047140357,
"last_content_update": 1686049083340,
"read_only": false,
"read_only_alternatives": []
}

5
.Rproj.user/178A6739/sources/session-99529da2/FE6BB309-contents

@ -20,11 +20,12 @@ library(stringr)
options(shiny.reactlog = TRUE, appDir = getwd())
source("mod_basic.R")
source("panel.R")
# source("mod_basic.R")
# source("secretary.R")
# source("forplumber.R")
# source("modals.R")
source("modals.R")
# Adding initial data

24
.Rproj.user/178A6739/sources/session-99529da2/FEF97A26

@ -0,0 +1,24 @@
{
"id": "FEF97A26",
"path": "~/Projects/LoanRisk/mod_basic.R",
"project_path": "mod_basic.R",
"type": "r_source",
"hash": "1266759796",
"contents": "",
"dirty": false,
"created": 1686047786220.0,
"source_on_save": false,
"relative_order": 3,
"properties": {
"source_window_id": "",
"Source": "Source"
},
"folds": "",
"lastKnownWriteTime": 1637757473,
"encoding": "UTF-8",
"collab_server": "",
"source_window": "",
"last_content_update": 1637757473,
"read_only": false,
"read_only_alternatives": []
}

141
.Rproj.user/178A6739/sources/session-99529da2/FEF97A26-contents

@ -0,0 +1,141 @@
# Module for a graph
# Module to show some stats
basicstatUI <- function(id) {
ns <- NS(id)
fluidRow(
h3("No of Assets"),
br(),
p(
"This section shows some basic information about the portfolio."
),
plotOutput(ns("statplot")),
verbatimTextOutput(ns("balancetext"))
)
}
basicstatServer <- function(id, dt) {
moduleServer(id,
function(input, output, session) {
df <- reactive({
dt %>%
ungroup() %>%
arrange(id, report_date) %>%
group_by(id) %>%
slice_max(report_date, n = 1) %>%
mutate(yr = lubridate::year(origination_date))
})
output$statplot <- renderPlot({
req(!is.null(df))
withProgress(message = "Plotting some graphs",
detail = "Won't take long",
value = 0,
{
setProgress(value = 1, message = "1 of 3..")
p1 <-
df() %>%
group_by(yr, loan_status) %>%
summarise(no_of_loans = n()) %>%
ungroup() %>%
ggplot(aes(
x = yr,
y = no_of_loans,
label = no_of_loans,
fill = factor(
loan_status,
levels = c("0", "1"),
labels = c("Good", "Bad")
)
)) +
geom_col(position = "dodge") +
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) +
labs(title = "No. of assets by year",
x = "Year",
y = "#") +
theme_bw() +
theme(legend.position = "none")
setProgress(value = 2, message = "2 of 3..")
p2 <-
df() %>%
group_by(asset_type, loan_status) %>%
summarise(no_of_loans = n()) %>%
ungroup() %>%
ggplot(aes(
x = asset_type,
y = no_of_loans,
label = no_of_loans,
fill = factor(
loan_status,
levels = c("0", "1"),
labels = c("Good", "Bad")
)
)) +
geom_col(position = "dodge") +
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) +
labs(title = "No. of assets by asset type",
x = "Asset Type",
y = "#") +
theme_bw() +
theme(legend.position = "none")
setProgress(value = 3, message = "3 of 3..")
p3 <-
df() %>%
group_by(customer_type, loan_status) %>%
summarise(no_of_loans = n()) %>%
ungroup() %>%
ggplot(
aes(
x = customer_type,
y = no_of_loans,
label = no_of_loans,
fill = factor(
loan_status,
levels = c("0", "1"),
labels = c("Good", "Bad")
)
)
) +
geom_col(position = "dodge") +
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) +
labs(title = "No. of assets by customer type",
x = "Customer Type",
y = "#") +
theme_bw() +
theme(legend.position = "bottom",
legend.title = element_blank())
setProgress(value = 4, message = "Patching..")
p4 <- p1 / (p2 | p3)
setProgress(value = 5, message = "Done..")
})
p4
})
output$balancetext <- renderText({
paste0(
"Total assets (no.): ",
length(unique(df()$id)) ,
"\n",
"Total balance outstanding: ",
round(sum(df()$balance) / 1000000, 2),
" M"
)
})
})
}

5
app.R

@ -20,11 +20,12 @@ library(stringr)
options(shiny.reactlog = TRUE, appDir = getwd())
source("mod_basic.R")
source("panel.R")
# source("mod_basic.R")
# source("secretary.R")
# source("forplumber.R")
# source("modals.R")
source("modals.R")
# Adding initial data

141
mod_basic.R

@ -0,0 +1,141 @@
# Module for a graph
# Module to show some stats
basicstatUI <- function(id) {
ns <- NS(id)
fluidRow(
h3("No of Assets"),
br(),
p(
"This section shows some basic information about the portfolio."
),
plotOutput(ns("statplot")),
verbatimTextOutput(ns("balancetext"))
)
}
basicstatServer <- function(id, dt) {
moduleServer(id,
function(input, output, session) {
df <- reactive({
dt %>%
ungroup() %>%
arrange(id, report_date) %>%
group_by(id) %>%
slice_max(report_date, n = 1) %>%
mutate(yr = lubridate::year(origination_date))
})
output$statplot <- renderPlot({
req(!is.null(df))
withProgress(message = "Plotting some graphs",
detail = "Won't take long",
value = 0,
{
setProgress(value = 1, message = "1 of 3..")
p1 <-
df() %>%
group_by(yr, loan_status) %>%
summarise(no_of_loans = n()) %>%
ungroup() %>%
ggplot(aes(
x = yr,
y = no_of_loans,
label = no_of_loans,
fill = factor(
loan_status,
levels = c("0", "1"),
labels = c("Good", "Bad")
)
)) +
geom_col(position = "dodge") +
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) +
labs(title = "No. of assets by year",
x = "Year",
y = "#") +
theme_bw() +
theme(legend.position = "none")
setProgress(value = 2, message = "2 of 3..")
p2 <-
df() %>%
group_by(asset_type, loan_status) %>%
summarise(no_of_loans = n()) %>%
ungroup() %>%
ggplot(aes(
x = asset_type,
y = no_of_loans,
label = no_of_loans,
fill = factor(
loan_status,
levels = c("0", "1"),
labels = c("Good", "Bad")
)
)) +
geom_col(position = "dodge") +
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) +
labs(title = "No. of assets by asset type",
x = "Asset Type",
y = "#") +
theme_bw() +
theme(legend.position = "none")
setProgress(value = 3, message = "3 of 3..")
p3 <-
df() %>%
group_by(customer_type, loan_status) %>%
summarise(no_of_loans = n()) %>%
ungroup() %>%
ggplot(
aes(
x = customer_type,
y = no_of_loans,
label = no_of_loans,
fill = factor(
loan_status,
levels = c("0", "1"),
labels = c("Good", "Bad")
)
)
) +
geom_col(position = "dodge") +
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) +
labs(title = "No. of assets by customer type",
x = "Customer Type",
y = "#") +
theme_bw() +
theme(legend.position = "bottom",
legend.title = element_blank())
setProgress(value = 4, message = "Patching..")
p4 <- p1 / (p2 | p3)
setProgress(value = 5, message = "Done..")
})
p4
})
output$balancetext <- renderText({
paste0(
"Total assets (no.): ",
length(unique(df()$id)) ,
"\n",
"Total balance outstanding: ",
round(sum(df()$balance) / 1000000, 2),
" M"
)
})
})
}

104
modals.R

@ -0,0 +1,104 @@
# 2nd modal
modal2<-modalDialog(
title = "File formatting",
fluidRow(
column(
width = 6,
p("Transactions file"),
varSelectInput("transid","Select id column", NULL),
varSelectInput("reportdate","Select report date column", NULL),
varSelectInput("origindate","Select origin date column", NULL),
varSelectInput("maturitydate","Select maturity date column", NULL),
varSelectInput("assettype","Select asset classifier column", NULL),
varSelectInput("customertype","Select customer classifier column", NULL),
varSelectInput("otherfact","Select any other classifier column", NULL, multiple = T)
),
column(
width = 6,
p("Transactions file"),
varSelectInput("bureauscore","Select bureau score column", NULL),
varSelectInput("balance","Select asset balance column", NULL),
varSelectInput("status","Select loan status column", NULL),
varSelectInput("defaultflag","Select default flag column", NULL),
radioButtons("dateformat","Select date format",choices = c("dmy","ymd"), selected = "ymd", inline = T),
p("Collateral File"),
varSelectInput("collateralid","Select id column", NULL),
varSelectInput("collateralvalue","Select Collateral value column", NULL)
)
),
easyClose = F,
size = "l",
footer = tagList(
actionButton("confirmupload", "Confirm"),
actionButton("closemodal2","Close")
)
)
modal1<- modalDialog(
title = "Upload files",
fluidRow(
column(
width = 6,
p("Add Transaction file"),
fileInput("transaction", "Choose CSV File of transactions",
multiple = F,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
p("Add Collateral file"),
fileInput("collaterals", "Choose CSV File of collaterals",
multiple = F,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
checkboxInput("header", "Header", TRUE),
fluidRow(
column(
width = 6,
radioButtons("sep", "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ",")
),
column(
width = 6,
radioButtons("quote", "Quote",
choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"')
)
)
),
column(
width = 6,
fluidRow(
tags$div(
"Following columns are required in the transaction file",
tags$ul(
tags$li("A unique identifier of asset (id)"),
tags$li("Date on which last report was generated. The last reporting date of all the assets must be same."),
tags$li("Origination Date"),
tags$li("Maturity Date"),
tags$li("Default flag i.e. whether previously defaulted"),
tags$li("Bureau/internal credit score"),
tags$li("Current loan status (1 is bad and 0 is good)"),
tags$li("Asset classification"),
tags$li("Customer classification"),
tags$li("Asset balance")
),
"The collateral file should contain present value of the collateral/possible price of sales of the asset/sales of hypothecated asset etc."
)
)
)
),
easyClose = F,
size = "l",
footer = tagList(
actionButton("uploadfiles", "Proceed"),
actionButton("closemodal1","Close")
)
)

126
panel.R

@ -48,67 +48,67 @@ panel1<-
")
)
),
))#,
# tags$hr(),
# fluidRow(
# column(
# width = 6,
# fluidRow(
# h3("Data"),
# br(),
# p("This section shows the data (uploaded or inbuilt sample).")
# ),
# br(),
# withSpinner(dataTableOutput("up_data"),type = 7,
# color = "black"),
# br(),
# actionButton("uploadnew", "Upload New Data", class="btn-light")
# ),
# column(width = 6,
# br(),
# basicstatUI("nofloans"))
#
# ),
# br(),
# br(),
# fluidRow(
# column(
# width = 6,
# h3("With Macroeconomic data"),
# p(
# "In this section, we add macroeconomic data. Please select the country of the asset and click on fetch button. If download fails, click again or try after sometime. Please note that GDP data has been discontinued by IMF recently. Hence, using Industrial output temporarily."
# ),
# column(
# width = 6,
# selectInput(
# "country",
# "Country",
# selected = "India",
# choices = countries$Country
# )
# ),
# column(
# width = 6,
# br(),
# actionButton("fetchimf", "Fetch IMF data", class = "glow")
# ),
# withSpinner(
# dataTableOutput("fulldata"),
# type = 7,
# color = "black"
# )
# ),
# column(width = 6,
# uiOutput("ac_button"),
# uiOutput("expcalcu"))
# ),
# br(),
# br(),
# fluidRow(column(width = 11,
# uiOutput("scenario_opts"))),
# br(),
# fluidRow(column(width = 11,
# uiOutput("credit_loss"))),
# fluidRow(column(width = 11,
# uiOutput("dlmanager")))
)),
tags$hr(),
fluidRow(
column(
width = 6,
fluidRow(
h3("Data"),
br(),
p("This section shows the data (uploaded or inbuilt sample).")
),
br(),
withSpinner(dataTableOutput("up_data"),type = 7,
color = "black"),
br(),
actionButton("uploadnew", "Upload New Data", class="btn-light")
),
column(width = 6,
br(),
basicstatUI("nofloans"))
),
br(),
br(),
fluidRow(
column(
width = 6,
h3("With Macroeconomic data"),
p(
"In this section, we add macroeconomic data. Please select the country of the asset and click on fetch button. If download fails, click again or try after sometime. Please note that GDP data has been discontinued by IMF recently. Hence, using Industrial output temporarily."
),
column(
width = 6,
selectInput(
"country",
"Country",
selected = "India",
choices = countries$Country
)
),
column(
width = 6,
br(),
actionButton("fetchimf", "Fetch IMF data", class = "glow")
),
withSpinner(
dataTableOutput("fulldata"),
type = 7,
color = "black"
)
),
column(width = 6,
uiOutput("ac_button"),
uiOutput("expcalcu"))
),
br(),
br(),
fluidRow(column(width = 11,
uiOutput("scenario_opts"))),
br(),
fluidRow(column(width = 11,
uiOutput("credit_loss"))),
fluidRow(column(width = 11,
uiOutput("dlmanager")))
)
Loading…
Cancel
Save