Data upload, download, display, modals and modules added.
This commit is contained in:
@@ -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": []
|
||||
}
|
||||
@@ -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")))
|
||||
)
|
||||
@@ -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": []
|
||||
}
|
||||
@@ -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
Normal file
24
.Rproj.user/178A6739/sources/session-99529da2/FEF97A26
Normal file
@@ -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
Normal file
141
.Rproj.user/178A6739/sources/session-99529da2/FEF97A26-contents
Normal file
@@ -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"
|
||||
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user