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

DataGrid not showing using ui.output_data_frame #764

Open
remylegoff opened this issue Oct 16, 2023 · 6 comments
Open

DataGrid not showing using ui.output_data_frame #764

remylegoff opened this issue Oct 16, 2023 · 6 comments

Comments

@remylegoff
Copy link

I'm using DataGrid and render.data_frame to be able to do row selection but the data frame is not displaying. When debugging, the returned object is a DataGrid shiny object. If I'm using basic pd.DataFrame everything is right.

Here, the server part :

@output
@render.data_frame
def feature_selection():
  meth = input.meth_graph()
  results = tranformed_data().dict_results[meth][2]
  to_return =  pd.DataFrame([raw_data().features,results]).T
  return render.DataGrid(
    to_return,
    row_selection_mode = 'multiple')

Here the ui part :

ui.nav(
  ui.row(
    ui.output_data_frame('feature_selection')
  )
)
@gshotwell
Copy link
Contributor

I'm not able to replicate this, can you post a more complete example?

This code works:

from shiny import module, ui, render, reactive, event, App, Inputs, Outputs, Session
import pandas as pd
import numpy as np

df = pd.DataFrame(
    {
        "A": np.random.rand(5),
        "B": np.random.rand(5),
        "C": np.random.rand(5),
        "D": np.random.rand(5),
        "E": np.random.rand(5),
        "F": np.random.rand(5),
    }
)

app_ui = ui.page_fluid(
    ui.output_data_frame("my_df"),
)


def server(input: Inputs, output: Outputs, session: Session):
    @output
    @render.data_frame
    def my_df():
        return render.DataGrid(df, row_selection_mode="multiple")


app = App(app_ui, server)

@remylegoff
Copy link
Author

here is a bit more of context from the ui part:

ui.navset_tab(
                                ui.nav('Données complètes', ui.output_data_frame('data_display')),
                                ui.nav(
                                    'Statistiques Descriptives',
                                    ui.page_fluid(
                                        ui.row(
                                            'Statistiques descriptives en retirant les 0',
                                            ui.output_data_frame('stats_descriptives')
                                            ),
                                        ui.row(
                                            'Visualisation graphiques',
                                            ui.input_text('col_boxplot','Colonnes à visualiser', placeholder = 'Séparées par ;'),
                                            ui.output_plot('boxplot')
                                            ),
                                        ui.row('Fréquence des différentes classes',
                                               ui.output_plot('frequence_classe'))
                                        )
                                    ),
                                ui.nav('Selection de variable',
                                       ui.output_data_frame('feature_selection'))
)

So it's in a big app with lot of tabs, sub tabs and it's the only thing not working.
The server part that is related to the display more than the render function is a bit too complex to put it here. But I don't think it comes from the server because the return object is a DataGrid

@remylegoff
Copy link
Author

remylegoff commented Oct 16, 2023

I'm using shiny 0.5.1, shinywidgets 0.2.1, pandas 2.0.3, python 3.11.4 on windows with VScode

@rh-atx
Copy link

rh-atx commented Oct 19, 2023

Hey @gshotwell I tried running your example, and unfortunately nothing rendered to the screen. I am also using shiny 0.5.1 and am experiencing this issue with render.DataGrid. I've noticed this only occurs when I'm using Safari, though. Thanks!

@gshotwell
Copy link
Contributor

@rh-atx I'm not able to reproduce that on Safari, is anything else different? Which version of Python are you on?

@remylegoff
Copy link
Author

Another forum post on the discord answer the question. The column names must be string and not index to work. I don't know if it will help improve the functions but when column names are transform to string, it works well.

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

3 participants