This project is meant for showcasing the integration of:
- Python FastApi,
- R-Shiny, (To use Plotly as the visualization package)
- React as front end for developing web pages
The application flow is as follows:
-
- User can uploadg market data for option pricing in a CSV format.
-
- Once the data is persisted into the database successfully, user can select a particular date to generate option prices.
-
- The option price plot is shown in the web page. The option prices can also be downloaded in a CSV file.
Object relation mapping(SQLAlchemy) is used to make the application portable and database technology agnostic. For simplicity, SQLLite db is used for storing the data in this demo. Due to the restrictions of available features in the free versions of R-Connrect and R-Shiny server, some workarounds are chosen that mayn't be good application design choices in real world implementations.
This application has following interactions.
- Market data loading and database persistence: React GUI to upload CSV files ----> FastAPI POST call to persist the data to a Database
- Fetch Unique dates: React dropdown list <----> FastAPI GET Call
- Display of Option Price Visualizations: React event trigger based on a date selected from the dropdown list <----> R-Shiny App(Plotly) <----> Fast API GET call fetch option prices
- Download calculated option prices in a CSV file: React paginated table <----> Fast API GET call.
See below screenshots of the application flow.
- A) Setup Python virtual environment by installing required packages
- B) Start FastApi server
Following commands can be used to perform these two steps:
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python .\src\api_manager.py
- Check on the link: http://127.0.0.1:8080/docs
Run R-Shiny application to create Plotly visuals. These plotly visuals are embedded into React web pages.
Note that in the free version of Shiny server, custom URLs are not allowed. Only one shiny app can run on one port. As a simple workaround, two Shiny apps are started separately to get Call and Put option pricing graphs on different ports.
Assuming that the user has installed R and required R packages such as Shiny and Plotly, set the current working folder to ".\RShiny_Plotly" in the command prompt and run the following R commands:
R Commands to run in R Studio Terminal to start Shiny Apps
- A) Setup React environment and install dependencies
- B) Start React server Go to the directory "react_frontend" and run the command terminal
npm install --legacy-peer-deps
npm start