{"id":7714,"library":"shinychat","title":"ShinyChat","description":"ShinyChat is a Python library that provides a Shiny toolkit for building generative AI applications like chatbots and streaming content directly within Shiny applications. It offers easy-to-use chat UI components that integrate seamlessly with various LLM frameworks. The library is actively maintained with frequent updates, currently at version 0.2.9.","status":"active","version":"0.2.9","language":"en","source_language":"en","source_url":"https://github.com/posit-dev/shinychat","tags":["AI","Chatbot","Shiny","UI","LLM","Generative AI"],"install":[{"cmd":"pip install shinychat","lang":"bash","label":"Install core package"},{"cmd":"pip install shinychat[providers]","lang":"bash","label":"Install with LLM provider dependencies (e.g., pydantic)"},{"cmd":"pip install shiny","lang":"bash","label":"Install Shiny (shinychat is a dependency of shiny)"}],"dependencies":[{"reason":"Shinychat is a UI component for Shiny apps; basic functionality often relies on Shiny's ecosystem.","package":"shiny","optional":false},{"reason":"Required as of shinychat v0.2.9.","package":"python>=3.10","optional":false},{"reason":"Optional dependency for integrating with LangChain LLM providers.","package":"langchain>=1.0.0","optional":true},{"reason":"Highly recommended for interacting with LLM providers, though not strictly required for the basic chat UI.","package":"chatlas","optional":true},{"reason":"A soft dependency included in the `providers` extra, necessary for certain features (e.g., `chatlas.types.ToolResultDisplay`).","package":"pydantic","optional":true},{"reason":"Recommended for securely loading environment variables like API keys.","package":"python-dotenv","optional":true}],"imports":[{"note":"While `ui.Chat` also works if `shiny` is imported, `shinychat.express.Chat` is the direct path for `shinychat`'s primary quickstart. For `shiny.App` structure, `chat = ui.Chat()` is used within the `server` function, with `ui.chat_ui()` in `app_ui`.","wrong":"from shiny.ui import Chat","symbol":"Chat","correct":"from shinychat.express import Chat"}],"quickstart":{"code":"import os\nfrom shiny.express import ui\nfrom shinychat.express import Chat\n\n# Set some Shiny page options\nui.page_opts(\n    title=\"Hello ShinyChat Echo Bot\",\n    fillable=True,\n    fillable_mobile=True,\n)\n\n# Create a chat instance and display its UI\nchat = Chat(id=\"chat\")\nchat.ui(\n    messages=[\"Hello! I'm an echo bot. Type something and I'll repeat it!\"]\n)\n\n# Define a callback to run when the user submits a message\n@chat.on_user_submit\nasync def handle_user_input(user_input: str):\n    # Simply echo the user's input back to them\n    await chat.append_message(f\"You said: {user_input}\")\n\n# To run this app, save it as `app.py` and execute:\n# `uv shiny run --reload app.py` (if using uv)\n# or `python -m shiny run --reload app.py` (if using pip/python)","lang":"python","description":"This quickstart creates a simple ShinyChat application where the AI assistant acts as an echo bot, repeating whatever the user types. It demonstrates the basic setup of a `Chat` instance, displaying its UI, and handling user input with an asynchronous callback."},"warnings":[{"fix":"Initialize `Chat` without message-related parameters, and use `chat.ui(messages=...)` to set initial messages. Perform input/response transformations manually outside of `Chat` methods.","message":"Several `Chat` constructor parameters and related methods were deprecated in v0.2.0. This includes `Chat(messages=...)`, `Chat(tokenizer=...)`, all parameters to `.messages()`, and the `.transform_user_input` and `.transform_assistant_response` decorators.","severity":"deprecated","affected_versions":">=0.2.0"},{"fix":"If encountering import errors related to `pydantic` or `chatlas` types, ensure `pydantic` is installed by running `pip install shinychat[providers]` or `pip install pydantic`.","message":"`pydantic` is listed as a 'soft dependency' (optional, part of the `providers` extra) but can cause `ImportError` if not installed when using features like `chatlas.types.ToolResultDisplay`. This has been a recurring point of change across several minor versions.","severity":"gotcha","affected_versions":">=0.2.5"},{"fix":"Upgrade your Python environment to version 3.10 or newer.","message":"Shinychat now requires Python 3.10 or later. Running with older Python versions will result in a `RuntimeError` or `SyntaxError` depending on the code.","severity":"breaking","affected_versions":">=0.2.9"},{"fix":"Install or upgrade LangChain using `pip install 'langchain>=1.0.0'` or `pip install shinychat[langchain]`.","message":"When integrating with LangChain, ensure `langchain` version 1.0.0 or newer is installed. Older versions may lead to compatibility issues.","severity":"gotcha","affected_versions":">=0.2.9"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install `pydantic` by running `pip install pydantic` or `pip install shinychat[providers]`.","cause":"`pydantic` is a soft dependency for `shinychat`'s `providers` extra, and is required by `chatlas` types like `ToolResultDisplay`. If `pydantic` is not installed, this error occurs.","error":"ImportError: cannot import name 'ToolResultDisplay' from 'chatlas.types'"},{"fix":"Initialize `chat = Chat(id=\"chat\")` without the `messages` argument, then pass initial messages to the `chat.ui()` method: `chat.ui(messages=[\"Your initial message\"])`.","cause":"The `messages` parameter in the `Chat` constructor was deprecated in v0.2.0.","error":"TypeError: Chat() got an unexpected keyword argument 'messages'"},{"fix":"Install the `shiny` package: `pip install shiny`.","cause":"`shinychat` is built on top of `Shiny for Python`. If `shiny` is not installed, any imports from `shiny` or `shinychat.express` will fail.","error":"ModuleNotFoundError: No module named 'shiny.express' or 'ModuleNotFoundError: No module named 'shiny''"},{"fix":"Upgrade your Python environment to version 3.10, 3.11, or 3.12.","cause":"Shinychat v0.2.9 and later require Python 3.10 or newer.","error":"RuntimeError: Python version 3.9 or earlier is not supported by shinychat."}]}