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

More Flexibility with Data Table Sorting Order with np.nan #1833

Open
KimberlyEddleman opened this issue Jan 30, 2025 · 0 comments
Open

More Flexibility with Data Table Sorting Order with np.nan #1833

KimberlyEddleman opened this issue Jan 30, 2025 · 0 comments

Comments

@KimberlyEddleman
Copy link

KimberlyEddleman commented Jan 30, 2025

When having a numeric column in a dataframe, the default for sorting seems to be to have negative values sorted, then np.nan or none values, then positive values. I get this is default behavior in pandas, but it makes the dataframes a bit cumbersome to view when I have some columns with a lot of blank values but also negative and positive values (big gap between my populated data). However, I don't want to filter the entire row out, since other columns of that row do have valid values.

The update_sort you added allows for sorting by multiple columns with buttons, but doesn't change the underlying behavior of the sort.

Is there any way to add an argument, such as na_position=last, so that blank values can go to the end?

Here is a basic example to illustrate what I am asking:

from shiny import App, render, ui
import pandas as pd
import numpy as np
data = {
    'ID': range(1, 11),
    'Name': ['Item ' + str(i) for i in range(1, 11)],
    'Value': [10.5, -5.2, np.nan, 15.7, -8.3, np.nan, 22.1, -12.4, 7.8, -3.9]
}
df = pd.DataFrame(data)

app_ui = ui.page_fluid(
    ui.h2("Data Grid Example"),
    ui.card(
        ui.output_data_frame("grid")
    )
)

def server(input, output, session):
    @output
    @render.data_frame
    def grid():
        return render.DataGrid(df)

app = App(app_ui, server) 

In this example, the sort will look like this:

Image

However, ideally, I'd like the na_position=last option so the blanks would be at the end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant