Coder Social home page Coder Social logo

triptych / streamlit-component-svelte-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 93degree/streamlit-component-svelte-template

0.0 1.0 0.0 169 KB

Template for building Streamlit components using Svelte for the component's frontend.

Python 21.51% HTML 14.40% JavaScript 8.14% TypeScript 55.95%

streamlit-component-svelte-template's Introduction

Streamlit Component Svelte Template

This repo contains a template and example code for creating Streamlit components using Svelte (+ Typescript) for the component's frontend.

It replicates the component from the Streamlit official templates. It relies on Svelte Rollup template and is inspired by the use of Svelte in Fanilo Andrianasolo's Named Entity Selection Component.

For complete information, please see the Streamlit Components documentation!

Overview

A Streamlit Component is made out of a Python API and a frontend (built using any web tech you prefer).

A Component can be used in any Streamlit app, can pass data between Python and frontend code, and can optionally be distributed on PyPI for the rest of the world to use.

  • Create a component's API in a single line of Python:
import streamlit.components.v1 as components

# Declare the component:
my_component = components.declare_component("my_component", path="frontend/public")

# Use it:
my_component(greeting="Hello", name="World")
  • Build the component's frontend out of HTML and JavaScript (or TypeScript, or ClojureScript, or whatever you fancy). In this case, with Svelte:
<script lang="ts">
  import { setStreamlitLifecycle } from "./streamlit";
  setStreamlitLifecycle();

  // Access arguments from Python
  export let greeting: string;
  export let name: string;
</script>

<div>{greeting}, {name}!</div>

Quickstart

  • Ensure you have Python 3.6+, Node.js, and npm installed.
  • Clone this repo.
  • Create a new Python virtual environment for the template:
$ python3 -m venv venv  # create venv
$ . venv/bin/activate   # activate venv
$ pip install streamlit # install streamlit
  • Initialize and run the component template frontend:
$ cd my_component/frontend
$ npm install    # Install npm dependencies
$ npm run dev    # Start the rollup dev server
  • From a separate terminal, run the template's Streamlit app:
$ . venv/bin/activate  # activate the venv you created earlier
$ streamlit run my_component/__init__.py  # run the example
  • If all goes well, you should see something like this: Quickstart Success
  • Modify the frontend code at my_component/frontend/src/MyComponent.svelte.
  • Modify the Python code at my_component/__init__.py.

Examples

  • COMING SOON

More Information

streamlit-component-svelte-template's People

Contributors

93degree avatar

Watchers

 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.