Code Monkey home page Code Monkey logo

shinylive-demoapp's Introduction

This repo provides an example of a Shinylive app. Shinylive enables to create a serverless Shiny applications with Python. Leveraging WebAssembly, it can run the Shiny app on the web browser without a server on the backend.

Example

Inspired by Prof. Richard McElreath's explanation about why normal distribution is normal in Statistical Rethinking chapter 3, created the following app:

The app is available here and with code on the shinylive editor

Why normal distributions are normal

Chapter 3 illustrates how to generate a normal distribution using the soccer field experiment:

  • Place a bunch of people at the center line of a soccer field
  • Each person flips a coin and moves one step to the right or left according to the outcome (head or tail)
  • Repeat this process multiple times

After a couple of iterations, you will notice the distribution of the people's distances across the field will become Gaussian or normal (e.g., bell-curved shape).

The app above simulates this experience by setting the sample size (i.e., number of people) and number of iterations. Where on each iteration, we draw a random number between -1 and 1 (can choose between float integer steps with the Step Type drop-down). The plot above shows the cumulative sum of each experiment across each step of the experience. You can notice how the distribution becomes more Gaussian as the number of steps increases.

Deploy shinylive app on Github Pages

As shinylive apps are serverless, you can deploy your app into Github Pages. First, create your app with the following step:

shiny create myapp

This will create the app file - app.py with the default shinylive example under the myapp folder:

.
└── myapp
    └── app.py

Next, update your app and build the site with the shiny static command:

shiny static myapp docs

We mapped the app folder - myapp to the website folder docs (Github Pages required the website name to set as docs). This will add the following folders:

.
├── docs
│   ├── edit
│   └── shinylive
│       ├── jquery.terminal
│       │   ├── bin
│       │   ├── css
│       │   └── js
│       ├── pyodide
│       │   └── fonts
│       ├── pyright
│       └── shiny_static
│           └── edit
└── myapp

You can test locally your app with the following command:

python3 -m http.server --directory docs 8008

and open on your browser using http://localhost:8008/.

Note: Any time you change your app, you will have to run shiny static myapp docs to update the docs folder.

Once you finilize your app, commit and push your changes and open your repo on Github and go to the Settings tab and select the Pages option (blue boxes):

Next, select under Build and deployment select the Deploy from branch option (green box) and under the branch option your branch you want to deploy from and the docs folder (purple box).

The site should be ready few minutes after with the following URL:

YOUR_GITHUB_USER_PROFILE.github.io/YOUR_REPO_NAME

The URL for the example above available here: https://ramikrispin.github.io/shinylive/

shinylive-demoapp's People

Contributors

ramikrispin avatar gvelasq avatar

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.