Code Monkey home page Code Monkey logo

fastapi_react_rshiny_plotly's Introduction

Python Build

Application Setup Instructions

This project is meant for showcasing the integration of:

  1. Python FastApi,
  2. R-Shiny, (To use Plotly as the visualization package)
  3. React as front end for developing web pages

The application flow is as follows:

    1. User can uploadg market data for option pricing in a CSV format.
    1. Once the data is persisted into the database successfully, user can select a particular date to generate option prices.
    1. 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.

  1. Market data loading and database persistence: React GUI to upload CSV files ----> FastAPI POST call to persist the data to a Database
  2. Fetch Unique dates: React dropdown list <----> FastAPI GET Call
  3. 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
  4. Download calculated option prices in a CSV file: React paginated table <----> Fast API GET call.

See below screenshots of the application flow.

Instrunctions to setup FastApi server, R-Shiny server and React Server.

Step 1: Setup Python environment and Run FastApi server

Starting the Python FastApi Server

  • A) Setup Python virtual environment by installing required packages
  • B) Start FastApi server

Following commands can be used to perform these two steps:

Commands to create and start the Python Virtual Environment and to run the FastAPI server

python -m venv .venv
.\.venv\Scripts\Activate.ps1
python .\src\api_manager.py

Check if FastApi server is properly running

Step 2: Run R-Shiny for enabling Plotly visualizations

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

Step 3: Install React dependencies and run React Server.

  • 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 

Screen shots of the application

FastAPI Swagger UI

Market Data Analysis page-1

Market Data Analysis page-2

<script async src="react_frontend/src/analytics.js"></script>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.