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

Shiny express app with trailing comma shows weird text output #88

Open
gshotwell opened this issue Dec 1, 2023 · 1 comment
Open

Shiny express app with trailing comma shows weird text output #88

gshotwell opened this issue Dec 1, 2023 · 1 comment

Comments

@gshotwell
Copy link
Contributor

Instead of erroring this says:

(<div class="form-group shiny-input-container">
  <label class="control-label" id="n-label" for="n">Number of rows to display</label><input id="n" type="number" class="shiny-input-number form-control" value="20"/>
</div>,)

https://shinylive.io/py/editor/#code=NobwRAdghgtgpmAXGKAHVA6VBPMAaMAYwHsIAXOcpMAMwCdiYACAZwAsBLCbJjmVYnTJM6cKITIcAbnDwjKAEzh05AVw4AdCHwFCmqKBAVQWTE-oVb6jVp24Y4AD1SiWpnYOFdUqsnIA2UNjEvlphEOoY3r4A+hHwdByEABQakGlyaQByqjAARspMxDQixADupmTETAocLKiB2BlMAEwADACUeOFaAAKiRsoYxmRQMfSwcExaSiWolADm6hAsMQo0yR2IWky7NSUAvBYYACJQowBidJPJIDt7DwDkAIKPiEzAAIxyLXIAzABdboQB5PABCbw+ABY5ABWOQANiB91BTEeAGFIcAAOxyAAccgAnACUUwAL4dUmiMiqOgg9ZgMkAoA

@wch
Copy link
Collaborator

wch commented Dec 2, 2023

I see what the problem is. This is the line in question:

ui.input_numeric("n", "Number of rows to display", 20),

In Python, the trailing comma there is shorthand for a creating a tuple with just one element, so that line is equivalent to:

(ui.input_numeric("n", "Number of rows to display", 20), )

So it's not Shiny doing anything weird here -- it's just Python itself supporting a strange syntax.


Full app for reference:

from shiny import reactive, render, ui
import pandas as pd
from shiny.express import input, layout


ui.input_numeric("n", "Number of rows to display", 20),


@render.data_frame 
def penguins_df():
    df = pd.DataFrame({
        'A': [1, 2, 3],
        'B': [4, 5, 6],
        'C': [7, 8, 9]
    })
    return df

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

No branches or pull requests

2 participants