Comments (4)
At this point
input.<tableID>_selected_rows()
stopped working and is no longer updating any reactive function.
Yes. It was removed without warning. Sorry 'bout that!
I'll restore it for the next release and add a clear news item about removing it in a future release.
[I'd like to have access to the selected rows]
Good news...
With a combination of
py-shiny/shiny/render/_data_frame.py
Lines 405 to 412 in 3b742a2
py-shiny/shiny/render/_data_frame.py
Lines 492 to 502 in 3b742a2
.data_view_indices(*, selected: bool = False)
? (Similar to .data_view(*, selected: bool = False)
)
It could return a {rows: list[int], cols: list[int]}
object containing all rows/cols being used (given selected
value). We could add a type
to describe how the values were selected, similar to the CellSelection
type
py-shiny/shiny/render/_data_frame_utils/_selection.py
Lines 162 to 185 in 3b742a2
For the return value, I still don't know if rows
and cols
should always exist (containing all values). If they always exist, it is easier to code as a user. If they do not exist, it is much clearer as to what is being subsetted but more annoying to integrate with as a user. I'm currently leaning towards always including rows
and cols
containing all values being used. Ex: multi row selection would return {type: "row", rows: [1,3,5], cols: [0,1,2,3,4,5]}
assuming we selected rows 1, 3, and 5 and there were 6 columns.
class DataViewIndices(TypedDict):
type: Literal["row", "col", "rect", "none"]
rows: ListOrTuple[int]
cols: ListOrTuple[int]
# class data_frame...
def data_view_indices(self, *, selected: bool = False) -> DataViewIndices:
...
@pstorozenko Glad you like .data_view()
!
It's not a problem for now, but if one day we shiny switches to some dataframe representation without creature like
pd.Index
it may be.
Can I get a copy of your crystal ball? 😆
I'd love to move to something like https://github.com/data-apis/dataframe-api-compat , however to get typing support, their typing specification is defined deep within another repo: https://github.com/data-apis/dataframe-api/tree/main/spec/API_specification/dataframe_api .
I do not understand why the types being used within dataframe-api-compat
are not shipped with the package. /rant
from py-shiny.
Shiny 0.9.0 introduced many new DataTable features, which includes new syntax for retrieving the selected rows. The new syntax is much more flexible in the sense that it both allows finer grained control over what types of selections are allowed and makes it possible to retrieve the selected rows, columns or cells on the server side.
The best example currently lives in the API reference: https://shiny.posit.co/py/api/core/render.DataGrid.html. We definitely need to update the examples in the components gallery to match the new syntax.
Here's an updated version of the demo example you linked to:
from palmerpenguins import load_penguins
from shiny import render
from shiny.express import input, ui
penguins = load_penguins()
ui.h2("Palmer Penguins")
@render.ui
def rows():
rows = penguins_df.data_view(selected=True) # <2>
selected = ", ".join(str(i) for i in sorted(rows.index)) if not rows.empty else "None" # <3>
return f"Rows selected: {selected}"
@render.data_frame
def penguins_df():
return render.DataTable(penguins, selection_mode="rows") # <1>
Notice that:
- In
render.DataTable()
we now useselection_mode
to specify what selections types are allowed. - Rather than using
input.{data_frame_id}_selected_rows()
, we now let you refer to the output directly, with a much richer API for interacting with the data table. Above, I usedpenguins_df.data_view(selected=True)
to get the selected rows from the current view (which may be filtered). - The return value from the
.data_view()
method is a complete table, which is generally more useful than the indices alone. That said, you can still userows.index
to get the indices, which were used in the example to just list which rows were selected.
from py-shiny.
I'd like to throw my bit here.
- I definitely prefer
.data_view(...)
accessor than some random*_selected_rows()
:D Thanks for working on this! - However, with
_selected_rows()
it was possible to get the indices of selected rows easily. Now I have to rely on pandas index for this. Why it's important to have such feature? Sometimes the displayed dataframe shows just a subset of columns of some dataframe in memory. Or rows in the dataframe correspond to some other objects (in my particular case each row represents an image, but you get the abstraction). It's not a problem for now, but if one day we shiny switches to some dataframe representation without creature likepd.Index
it may be. - ☝🏻 The breaking changes section of 0.9.0 release mentions only
selection_mode
(which is actually deprecation, not breaking), but says nothing about_selected_rows()
/.data_view()
which made it much harder for me to trace the issue.
Cheers!
from py-shiny.
Original issue is being fixed in #1377 .
Making new issue for .data_view_info()
support
from py-shiny.
Related Issues (20)
- data_frame coerces datetimes to integers HOT 1
- Issue unpickling a wrapped keras model into a Shiny app HOT 1
- Dev docs should be deployed at GitHub pages root
- Request: File Browser Example?
- `shiny.ui.Chat`, part 2
- Move py-shiny specific assets from `www/shared/py-shiny` to `www/py-shiny`
- Data_frame with two tables in edit mode, hangs browser. Potential Bug? HOT 5
- Modify GitHub Actions Workflow to leverage draft mode status and remove merge queue HOT 1
- [express]: how to put a sidebar in a `navset_card_tab()` context manager? HOT 1
- Help Dynamically Inserting and Removing Nav_Panel Tabs
- feat(data frame): Add support for `narwhals` and `ibis`
- Adding startup `Chat(messages=...)` leads to error on shinylive
- Remove `@output` from Python/R comparison article
- AttributeError: module 'shiny.ui' has no attribute 'input_task_button'. Did you mean: 'input_action_button'? HOT 3
- Question: Adding a footnote to the shiny-server landing page?
- Empty `input_date()` crashes Shiny HOT 1
- Docs overview page crashes on Safari on iPad HOT 6
- Broken link from docs overview to playground
- some values in DataGrid displayed as 0 HOT 1
- `remove_all_fill(tag)` modifies `tag` in place
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from py-shiny.