Skip to content

Instantly share code, notes, and snippets.

@javier-henao
Last active May 16, 2026 05:35
Show Gist options
  • Select an option

  • Save javier-henao/0defc486ba93fc782115c7821305c30e to your computer and use it in GitHub Desktop.

Select an option

Save javier-henao/0defc486ba93fc782115c7821305c30e to your computer and use it in GitHub Desktop.
STREAMLIT: Configuración Inicial

Configuración de Entorno Python + Streamlit

Gestión del Proyecto

Crear carpeta del proyecto

mkdir "name"

Acceder a la carpeta del proyecto

cd "name"

Python

Verificar instalación de Python

python3 --version

Crear entorno virtual

python3 -m venv .venv

Activar el entorno virtual

source .venv/bin/activate

Desactivar el entorno virtual

deactivate

Instalación de Dependencias

Instalar Streamlit

pip install streamlit

Actualizar pip

pip install --upgrade pip

Instalar Watchdog

pip install watchdog

Configuración en VS Code

Seleccionar intérprete de Python

  1. Presiona ⌘ + P
  2. Escribe >Python: Select Interpreter
  3. Selecciona el intérprete recomendado: .venv

Crear Archivo de la Aplicación, desde terminal

touch app.py

Ejecutar la Aplicación

streamlit run app.py

Alternativa si el comando anterior no funciona:

python -m streamlit run app.py

Estructura de Carpetas — Proyecto Multipage

nombre-proyecto/
├── app.py                  # Punto de entrada principal
├── requirements.txt        # Dependencias del proyecto
├── railway.json            # Configuración de despliegue
├── .venv/                  # Entorno virtual (no subir a GitHub)
├── .gitignore              # Archivos ignorados por Git
└── pages/
    ├── menu_pages.py       # Configuración de navegación
    ├── home.py             # Página de bienvenida
    ├── page1.py            # Página 1
    ├── page2.py            # Página 2
    └── page3.py            # Página 3

Contenido mínimo de app.py

import streamlit as st
from pages.menu_pages import build_navigation

st.set_page_config(
    page_title="Nombre App",
    page_icon=":material/home:"
)

page = build_navigation()
page.run()

Contenido mínimo de pages/menu_pages.py

import streamlit as st

def build_navigation():
    home  = st.Page(title="Inicio",   page="pages/home.py",
                    icon=":material/home:", default=True)
    page1 = st.Page(title="Página 1", page="pages/page1.py",
                    icon=":material/check_circle:")

    return st.navigation(
        {"": [home], "Sección 1": [page1]},
        position="top"
    )

Crear .gitignore

cat > .gitignore << 'EOF'
.venv/
__pycache__/
*.pyc
.DS_Store
.env
EOF

Reglas clave:

  • set_page_config solo en app.py, antes de todo
  • st.navigation solo dentro de una función, nunca en el cuerpo del módulo
  • Las subpáginas no llaman set_page_config ni st.navigation

Despliegue en Railway

Verificar Git instalado

git --version

Generar requirements.txt desde el entorno virtual

source .venv/bin/activate
pip freeze > requirements.txt
cat requirements.txt

Crear railway.json

cat > railway.json << 'EOF'
{
  "$schema": "https://railway.app/railway.schema.json",
  "build": {
    "builder": "NIXPACKS"
  },
  "deploy": {
    "startCommand": "streamlit run app.py --server.address 0.0.0.0 --server.port $PORT --server.fileWatcherType none --browser.gatherUsageStats false"
  }
}
EOF

Inicializar repositorio Git

git init
git add .
git commit -m "initial commit"

Crear repo en GitHub y conectarlo

En GitHub crea un repo vacío (sin README), luego:

git remote add origin https://github.com/TU_USUARIO/TU_REPO.git
git branch -M main
git push -u origin main

Desplegar en Railway

# Instalar Railway CLI
npm install -g @railway/cli

# Login
railway login

# Crear proyecto nuevo
railway init

# Vincular al repo (si ya lo creaste desde GitHub)
railway link

# Desplegar
railway up

Generar dominio público

railway domain

Genera una URL tipo tu-proyecto.up.railway.app

Ver logs en tiempo real

railway logs

Actualizaciones futuras

Cada vez que hagas cambios:

git add .
git commit -m "descripcion del cambio"
git push

Railway redespliega automáticamente al detectar el push en GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment