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

data table tutorial #304

Merged
merged 14 commits into from
Nov 29, 2023
Merged

data table tutorial #304

merged 14 commits into from
Nov 29, 2023

Conversation

tgberkeley
Copy link
Collaborator

No description provided.

@tgberkeley tgberkeley marked this pull request as ready for review November 14, 2023 02:01
@tgberkeley tgberkeley changed the title initial version of tutorial with no live streaming yet data table tutorial Nov 14, 2023
@tgberkeley tgberkeley requested a review from picklelo November 20, 2023 18:09
Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversational tone is a little bit too much for me throughout the tutorial. I think it's great to have a some, to make the reader feel they are part of something, but reading through, i need less "we" and "our" and more "the component ...", "this event handler ...", "the state defines a var, ...", etc.

This would break up the conversational tone with more precise language, without making the whole thing read like reference material.


Adding type hints on all event handlers would help the code examples stand on their own.




# Data Table Tutorial
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this isn't for the rx.data_table component, maybe the heading should be "Data Editor Tutorial"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this is something I discussed with nikhil, it is just that more commonly people refer to this component as a data table. Perhaps we could call it the data table (editable).

docs/datatable-tutorial/simple_table.md Outdated Show resolved Hide resolved
docs/datatable-tutorial/simple_table.md Outdated Show resolved Hide resolved
docs/datatable-tutorial/simple_table.md Outdated Show resolved Hide resolved
Comment on lines 29 to 32
1. title: The text to display in the header of the column
2. id: An id for the column, if not defined, will default to a lower case of title
3. width: The width of the column
4. type: The type of the columns, default to "str"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use code marks on the key names

Suggested change
1. title: The text to display in the header of the column
2. id: An id for the column, if not defined, will default to a lower case of title
3. width: The width of the column
4. type: The type of the columns, default to "str"
1. `title`: The text to display in the header of the column
2. `id`: An id for the column, if not defined, will default to a lower case of title
3. `width`: The width of the column (in pixels?)
4. `type`: The type of the columns, default to "str"

For type, how can i find out what types are available?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there more recognized keys for a column dict as well? where are those defined?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I can tell these are the only 4, but going through the reflex docs and the reflex code these are not actually defined anywhere that I can see so it is hard to say if there are more, we will need to chat to Thomas and ask

docs/datatable-tutorial/add_interactivity.md Show resolved Hide resolved

There are several other event triggers that are worth exploring. The `on_item_hovered` event trigger is called whenever the user hovers over an item in the datatable. The `on_delete` event trigger is called when the user deletes a cell from the datatable.

The final event trigger to check out is `on_column_resize`, this allows us to manually resize the width of our columns by hand. The event trigger returns the `col` we are adjusting and the new `width` we have defined. We then index into `self.cols` defined in our state and change the `width` of that column using this code: `self.cols[col['pos']]['width'] = width`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allows us to manually resize the width of our columns by hand

This sounds sort of funny to me.

Maybe something more like, "on_column_resize allows us to respond to the user dragging the handle between columns"

I think more description of the col arg is warranted, since it appears to be a dictionary, but not clear what is inside.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added both of these

By default there is a `vertical_border` between the columns, we can turn it off by setting this prop to `False`. We can define how many columns a user can select at a time by setting the `column_select` prop. It can take values of `"none", "single", "multi"`.

We can allow `overscroll_x`, which allows users to scroll past the limit of the actual horizontal content. There is an equivalent `overscroll_y`.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest directly linking to the component docs where all of these props (and more) are displayed in table form.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

docs/datatable-tutorial/add_styling.md Outdated Show resolved Hide resolved

Lastly let's add in an API so we can live stream data into our datatable.

Here we use a [Background Task](https://reflex.dev/docs/advanced-guide/background-tasks) to stream the data into the table without blocking UI interactivity. We call an advice API using `httpx` and then append that data to the `self.table_data` state var. We also create a button that allows us to start and pause the streaming of the data by changing the value of the boolean state var `running` using the event handler `toggle_pause`. If the `running` state var is set to `True` we stream the API data, when it is set to `False` we break out of the `while` loop and end the background event.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Here we use a [Background Task](https://reflex.dev/docs/advanced-guide/background-tasks) to stream the data into the table without blocking UI interactivity. We call an advice API using `httpx` and then append that data to the `self.table_data` state var. We also create a button that allows us to start and pause the streaming of the data by changing the value of the boolean state var `running` using the event handler `toggle_pause`. If the `running` state var is set to `True` we stream the API data, when it is set to `False` we break out of the `while` loop and end the background event.
Here we use a [Background Task](docs/advanced-guide/background-tasks) to stream the data into the table without blocking UI interactivity. We call an advice API using `httpx` and then append that data to the `self.table_data` state var. We also create a button that allows us to start and pause the streaming of the data by changing the value of the boolean state var `running` using the event handler `toggle_pause`. If the `running` state var is set to `True` we stream the API data, when it is set to `False` we break out of the `while` loop and end the background event.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually doesn't seem to work, so changed it back

tgberkeley and others added 12 commits November 21, 2023 12:36
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
@tgberkeley tgberkeley merged commit 74150d1 into main Nov 29, 2023
1 check passed
@Alek99 Alek99 deleted the datatable-tutorial branch December 20, 2023 04:07
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

Successfully merging this pull request may close these issues.

2 participants