This projects builds a basic business lending shiny app using shinyspring. This is a motivating example to get to build your first shinyspring app. This App demonstrates the following features of of shinyspring
- Template based code creation
- Menu creation in configuration files
- Wiring of Datasets
- Reuse of pre-built shiny modules
- Writing the Core App
This example does not demonstrate other features like Authentication , job scheduling(targets) and more as they get added.
This app is based on Bankruptcy Data of 5000+ companies. the data has been modified slightly so as to enable a rich demo and case for shinyspring. The datasets for the app can be found at link here
App Goals
-
Provide a Lending Risk Monitor Dashboard for a portfolio of loans spread across 5 countries.
-
Based on Bankruptcy default probability show the Value at Risk
Persona Board
Persona | Frequency of Visits | Reason to visit and Use | What is Awesome? | What would suck? |
---|---|---|---|---|
-
in R console run
shinyspring::create_new_project()
-
open the newly created
user_script.R
. make sure all the dependencies are installed as indicated in user_script -
open
config.yml
-
Adjust the following properties in config yml.
Dashboard Look and Feel
# Dashboard UI information : You should customize app_title: Credit Dashboard footer_left: Built on Shiny Spring footer_left_url: http://www.shinyspring.dev footer_right: 2021 sidebar_expand_onhover: FALSE dark_theme: FALSE header_href: https://www.shinyspring.dev header_image: https://storage.googleapis.com/shiny-pics/spring_logo.png header_fixed: 'TRUE' title_color: primary app_title_h3: Lending Monitoer side_bar_fixed: TRUE side_bar_header: Business Lending header_opacity: 0.8
Create Menu Structure
# Menus : You should customize - documentation here $TODO link # Note: the ui_function and server_function are from sweetmods or your custom modules menus: [ { title: Introduction , name: intro_tab , icon: leanpub }, { title: Lending Book , name: core_tab , icon: credit-card }, { title: Data Exploration , icon: chart-bar , parent_menu: true , sub_menu: [ {first: true ,submenu_title: Visualize , submenu_name: explore_tab , submenu_icon: circle-thin } , {last_submenu: true , submenu_title: Correlations , submenu_name: corr_tab , submenu_icon: cubes } , ] }, { title: Credits , name: credits_tab , icon: heart , last_menu: true } ]
For now leave the
explore_tab
andcorr_tab
the way way the are, we can adjust them later -
Run the rest of the commands in
user_script.r
. You will have a newapp.R
. You can run the shiny app in Rstudio or callshiny::runApp()
which will launch the app.
Wire the Dataset to shinyspring with the following update in config.yml
# datsets : This is the approach to pre-load datasets
ds.portfolio.type: rds
ds.portfolio.connection: data/portfolio.rds
ds.portfolio.ds_info_type: google
ds.portfolio.ds_info_url: https://docs.google.com/spreadsheets/d/17QhXC0b6a0WZGRSFGPA6KBdjq_lalm0TGi33hLBNsFI
-
Now run the application to see if dataset portolio is loaded correctly. You can check based on
-
Check 1: steps 2 to Step 5 in
user_script.R
should run without error and the Shiny app should get launched :white_check_mark: -
Check 2: When you run the App , you should be able to see the the
portfolio
dataset in the drop down in Data Explodation \ Visualize Menu . ✅ .
-
Notes: ds.portfolio.ds_info_type
and ds.portfolio.ds_info_url
in
config.yml are optional. They perform initial data validation and
provide an opportunity to clean colnames and provide “pretty_names” to
colums that are easily understood. Please refer to Configuring Datasets
document here # TODO Link
-
Create your custom shiny module needed for Lending Dashboard with
shinyspring::create_module("lending_mod")
in R console -
open
lending_mod.R
and browse skeleton code -
wire the
lending_mod
into the menu’s and application with the following changes inconfig.yml
core_tab.mod_name: lending_mod core_tab.ui_function: lending_mod_ui core_tab.server_function: lending_mod_server core_tab.onload_function: lending_mod_onLoad
the above 4 line items are needed or all modules to talk to shinyspring. For pre-built modules they are defined in package and hence you do not need to wire them explicitly here. Here is the module registry for pre-built modules. Browse these to get an idea how wiring modules to shinyspring. [Link here](https://docs.google.com/spreadsheets/d/15HXspcKqGyDYAM1Jfa7SFjCALHMWTPyTbjrXnWuHY2I/)
-
Now , let us write the core lending modules. Cut and paste the code from here (TODO) in your
lending_mod.R
file -
Finally , let us make sure that you source the
lending_mod.R
on app startup. Include the following linesource("lending_mod.R")
inon_startup.R
. on_startup.R was created when you created the project.