Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to update Chat()'s input placeholder #1594

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Jul 30, 2024

Via a new update_user_input() method. As a result, set_user_message() is now deprecated. Here's an example of using it to update the input's placeholder:

from shiny import App, module, reactive, ui


@module.ui
def chat_module_ui():
    return [
        ui.chat_ui("chat"),
        ui.input_action_button(id="placeholder_increment", label="Increment"),
    ]


@module.server
def chat_module_server(input, output, session):
    chat = ui.Chat(id="chat")

    @reactive.effect
    @reactive.event(input.placeholder_increment)
    def _():
        chat.update_user_input(
            placeholder=f"placeholder {input.placeholder_increment()}"
        )

    @chat.on_user_submit
    async def submit_chat():
        user = chat.user_input()
        await chat.append_message(f"You said: {user}")


app_ui = ui.page_fillable(
    ui.panel_title("Hello Shiny Chat"),
    chat_module_ui("chat_container"),
    fillable_mobile=True,
)

def server(input, output, session):
    chat_module_server("chat_container")

app = App(app_ui, server)

@cpsievert cpsievert marked this pull request as ready for review July 30, 2024 16:38
@cpsievert cpsievert requested a review from wch July 30, 2024 16:38
@cpsievert cpsievert merged commit 11d3e94 into main Aug 6, 2024
56 checks passed
@cpsievert cpsievert deleted the chat-update-user-input branch August 6, 2024 16:57
schloerke added a commit that referenced this pull request Aug 22, 2024
* main:
  refactor: `shiny create` and `shiny add test` supporting functions (#1629)
  Update CHANGELOG.md
  Fix #1601: Force text/javascript for .js files
  Work around griffe 1.0 breaking changes
  feat(shiny create): Support simpler syntax for `--github` flag (#1623)
  Make sure `Chat.messages(format='google')` converts role assistant -> model (#1622)
  Fix `NormalizerRegistry.register()` (#1619)
  Update JS/CSS from shiny and bslib (#1617)
  Add ability to update `Chat()`'s input placeholder (#1594)
  docs: Add double-quotes to shiny[theme] (#1605)
  `json.dump()` each websocket message once instead of twice (#1597)
schloerke added a commit to machow/py-shiny that referenced this pull request Sep 5, 2024
* main:
  setup.cfg -> pyproject.toml (posit-dev#1625)
  docs(navset): Add server function to navset docs (posit-dev#1596)
  Pin syrupy to avoid pytest-rerunfailures incompatibility (posit-dev#1632)
  refactor: `shiny create` and `shiny add test` supporting functions (posit-dev#1629)
  Update CHANGELOG.md
  Fix posit-dev#1601: Force text/javascript for .js files
  Work around griffe 1.0 breaking changes
  feat(shiny create): Support simpler syntax for `--github` flag (posit-dev#1623)
  Make sure `Chat.messages(format='google')` converts role assistant -> model (posit-dev#1622)
  Fix `NormalizerRegistry.register()` (posit-dev#1619)
  Update JS/CSS from shiny and bslib (posit-dev#1617)
  Add ability to update `Chat()`'s input placeholder (posit-dev#1594)
  docs: Add double-quotes to shiny[theme] (posit-dev#1605)
  `json.dump()` each websocket message once instead of twice (posit-dev#1597)
  docs: Update note on style keys allowing for kebab-case (posit-dev#1595)
  docs: fix navset function links (posit-dev#1590)
  Get `ui.Chat()` working inside Shiny modules (posit-dev#1582)
  bug(notification): Allow for duration to be `None` and passed to client (posit-dev#1577)
  Fix logic for detection of support files in docs (posit-dev#1580)
  docs(navset): Add examples for navset (posit-dev#1579)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants