Skip to content

Instantly share code, notes, and snippets.

View andfanilo's full-sized avatar
Crazy Streamlitin'

Fanilo Andrianasolo andfanilo

Crazy Streamlitin'
View GitHub Profile
@brunomsantiago
brunomsantiago / app.py
Last active December 1, 2023 11:29
Streamlit keyboard shortcuts to buttons (tested on streamlit 1.4.0)
import streamlit as st
import streamlit.components.v1 as components
def left_callback():
st.write('Left button was clicked')
def right_callback():
st.write('Right button was clicked')
This file has been truncated, but you can view the full file.
@ash2shukla
ash2shukla / state.py
Last active February 27, 2024 06:00
state decorator
from streamlit.report_thread import get_report_ctx
from streamlit.hashing import _CodeHasher
from streamlit.server.server import Server
from prometheus_client.registry import REGISTRY
from prometheus_client import Counter
class _SessionState:
def __init__(self, session, hash_funcs):
"""Initialize SessionState instance."""
@FranzDiebold
FranzDiebold / SessionState.py
Last active August 25, 2023 14:38 — forked from tvst/SessionState.py
A possible design for doing per-session persistent state in Streamlit
# https://gist.github.com/FranzDiebold/898396a6be785d9b5ca6f3706ef9b0bc
"""Hack to add per-session state to Streamlit.
Works for Streamlit >= v0.65
Usage
-----
>>> import SessionState
>>>
@andfanilo
andfanilo / deploy_streamlit_cc.md
Last active May 19, 2022 04:35
Steps to release Streamlit Custom Component package
  1. Pass flag _release to True
  2. Rebuild frontend:
cd package/frontend
rm -rf build/
npm run build
cd ../../
  1. Rebuild Python:
@swyxio
swyxio / Tailwindcssunreset.scss
Last active February 14, 2024 01:19
Tailwind CSS Un-Reset - un-reset Tailwind's Preflight CSS Reset so that autogenerated HTML looks consistent with the rest of your Tailwind site. - https://www.swyx.io/writing/tailwind-unreset
.unreset {
a {
@apply text-blue-700 underline;
}
p {
@apply my-4;
}
blockquote,
figure {
from tkinter import *
from PIL import ImageTk,Image
import time
import os
targetImageWidth = 850
targetImageHeight = 400
inputImageWidth = 0
inputImageHeight = 0
worker_processes 1;
events {
worker_connections 1024;
}
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
@tvst
tvst / SessionState.py
Last active September 30, 2024 07:47
DO NOT USE!!! Try st.session_state instead.
"""Hack to add per-session state to Streamlit.
Usage
-----
>>> import SessionState
>>>
>>> session_state = SessionState.get(user_name='', favorite_color='black')
>>> session_state.user_name
''
@jeff3dx
jeff3dx / d3-in-react.js
Last active October 27, 2022 09:24
D3 in React with Hooks
import React, { useRef, useEffect } from 'react';
import * as d3 from 'd3';
interface IProps {
data?: number[];
}
/* Component */
export const MyD3Component = (props: IProps) => {
/* The useRef Hook creates a variable that "holds on" to a value across rendering