Render widget return nothing (no error and no output)

Dear everyone, I've started to create my second application on python (Shiny) and for this one, I've created three files:

  • app.py
  • appback/ui.py
  • appback/server.py

All the project uses a virtual environment (python3.9). app.py looks like:

exec(open("backapp/ui.py").read())

exec(open("backapp/server.py").read())

# run the app :
www_dir = Path(__file__).parent / "www"
app = App(app_ui, server, static_assets=www_dir, debug=True)

So, my problem is I'm trying to use plotly and of course shinywidgets but when I'm trying to use this example split between ui.py and server.py, nothing appear except the input button.

Code in ui.py:

                ui.nav(
                    " DATA ",
                    ui.tags.div(
                            ui.tags.br(),
                            ui.tags.div(
                                ui.output_ui("table_viz"),
                                class_="card-style",
                            ),
                            ui.tags.br(),
                            ui.tags.div(
                                ui.row(
                                    ui.column(
                                        3,
                                        ui.input_radio_buttons(
                                            "timestart_1",
                                            "Starting date:",
                                            timeline,
                                        ),
                                    ),
                                    ui.column(
                                        3,
                                        ui.input_radio_buttons(
                                            "timeend_1",
                                            "Ending date:",
                                            timeline,
                                        ),
                                    ),
                                    ui.column(
                                        3,
                                        ui.tags.div(
                                            ui.input_switch(
                                                "newold",
                                                "Old (default) or new employees",
                                            ),
                                            ui.input_action_button(
                                                "timebutton",
                                                "Show",
                                                style="justify-content: center;",
                                            ),
                                            ui.tags.br(),
                                        ),
                                    ),
                                ),
                            ),
                            ui.tags.div(
                                ui.output_ui("timetable_viz"),
                                ui.input_checkbox(
                                    "show_fit", "Show fitted line", value=True
                                ),
                                output_widget("scatterplot"),
                                class_="card-style",
                            ),
                        ),
                    ),
                    icon=ui.tags.i(class_="glyphicon glyphicon-th-list"),
                ),

Code in server.py:

# Generate some data and fit a linear regression
n = 10000
dat = np.random.RandomState(0).multivariate_normal([0, 0], [(1, 0.5), (0.5, 1)], n).T
x = dat[0]
y = dat[1]
fit = LinearRegression().fit(x.reshape(-1, 1), dat[1])
xgrid = np.linspace(start=min(x), stop=max(x), num=30)

def server(input, output, session: Session):
    scatterplot = go.FigureWidget(
        data=[
            go.Scattergl(
                x=x,
                y=y,
                mode="markers",
                marker=dict(color="rgba(0, 0, 0, 0.05)", size=5),
            ),
            go.Scattergl(
                x=xgrid,
                y=fit.intercept_ + fit.coef_[0] * xgrid,
                mode="lines",
                line=dict(color="red", width=2),
            ),
        ],
        layout={"showlegend": False},
    )

    register_widget("scatterplot", scatterplot)

    @reactive.Effect
    def _():
        scatterplot.data[1].visible = input.show_fit()

To add something, when I replace app.py by the content of the example then it's work fine (I think there is no install problem). And every other things works fine in the app.

For me, two issues are possible:

1 - render_widget doesn't work because is inside an element of a ui.nav_menu,
2 - render_widget doesn't work because of ui and server split,

PS: It's a little bit complicated for me to provide my code but I could found a solution to this problem if it's necessary.

Maybe this

I've tried this morning and the issue is not related to the split but to ui.nav_menu. In fact if I put the render_widget outside it's working... Anyone know why?

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.