Toggle dark mode

Hi,

🎉 V2.0 is out. 

Check out our new release!

M
November 23, 2022

Using file_selector ‘on_action’ callback

Welcome to Taipy Forums Using Taipy Using file_selector ‘on_action’ callback

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #237127
    gmaraboutgmarabout
    Participant

    Hello!

    I have a newbie question related to file_selector/callbacks 🙂

    I want to use the file_selector to load a CSV file.
    Here is what I am currently doing:

    `
    contents = “””
    <|file_selector|label=Upload dataset|on_action=load_csv_file|extensions=.csv|>
    “””

    def load_csv_file(selection):
    dataset = pd.read_csv(selection)

    `

    However, the selection is not the selected file, but an (empty) _State_ object…
    Am I missing something?
    How should I get the selected path so that I can do something with it?

    Thanks for your help!

    Greg

    #237135
    Florian JactaFlorian Jacta
    Keymaster

    Hi Greg,

    I have created a little code for you to help you use this control. This control is attached to a Python variable (here “path”). The value will be the path of the selected file. The real-time value of “path” can be found in the State object as below. The State object contains every GUI variable used by the application (https://docs.taipy.io/en/latest/getting_started/step_02/ReadMe/#multi-client—state).

    ———–
    from taipy.gui import Gui
    import pandas as pd

    path = None

    md = “<|{path}|file_selector|label=Upload dataset|on_action=load_csv_file|extensions=.csv|>”

    def load_csv_file(state):
    data = pd.read_csv(state.path)
    print(data)

    Gui(md).run()
    ———–

    I hope that helps. If you need anything else, feel free to ask.
    Florian

    #237138
    gmaraboutgmarabout
    Participant

    Awesome! Thanks Florian!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.