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

bugfix for properly rendering datatables. #638

Merged

Conversation

ElijahAhianyo
Copy link
Collaborator

@ElijahAhianyo ElijahAhianyo commented Mar 6, 2023

This PR fixes the issue with how datatables are being rendered. The supported fields for the data prop are List, List[List], Dataframe. You should be able to add a datatable in the following manner:

import pynecone as pc


class State(pc.State):
    pass


def index() -> pc.Component:
    return pc.center(
        pc.vstack(
            pc.heading("My Chatbot"),
            pc.data_table(
                data= [["foo", "answer"],["foo2", "bar2"] ], columns = ["prompt", "answer"]
            ),
        ),
    )


app = pc.App(state=State)
app.add_page(index)
app.compile()
import pynecone as pc


class State(pc.State):
     data = [["foo", "answer"],["foo2", "bar2"] ]
     columns = ["prompt", "answer"]


def index() -> pc.Component:
    return pc.center(
        pc.vstack(
            pc.heading("My Chatbot"),
            pc.data_table(
                data=State.data, columns=State.columns
            ),
        ),
    )


app = pc.App(state=State)
app.add_page(index)
app.compile()
import pynecone as pc


class State(pc.State):
     data = ["foo", "bar"]
     columns = ["prompt", "answer"]


def index() -> pc.Component:
    return pc.center(
        pc.vstack(
            pc.heading("My Chatbot"),
            pc.data_table(
                data=State.data, columns=State.columns
            ),
        ),
    )


app = pc.App(state=State)
app.add_page(index)
app.compile()
import pynecone as pc
import pandas as pd


class State(pc.State):
     data = pd.Dataframe([["foo", "answer"],["foo2", "bar2"] ], columns = ["prompt", "answer"])
     
def index() -> pc.Component:
    return pc.center(
        pc.vstack(
            pc.heading("My Chatbot"),
            pc.data_table(
                data=State.data
            ),
        ),
    )


app = pc.App(state=State)
app.add_page(index)
app.compile()

NB:

  • When you set data as a pandas Dataframe, you don't have to pass in the columns props to the component.
  • When you set data as a List, its mandatory to pass in a columns field

Type of change

  • Bug fix (non-breaking change which fixes an issue)

fixes #620

@ElijahAhianyo ElijahAhianyo marked this pull request as ready for review March 7, 2023 21:02
Copy link
Contributor

@picklelo picklelo left a comment

Choose a reason for hiding this comment

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

looks good!

@picklelo picklelo merged commit e106b7a into reflex-dev:main Mar 7, 2023
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.

pc.datatable doesnt render grid properly with state vars
2 participants