Whoops…Nothing found

Try other keywords in your search

Get Values from Steps and Pages

 1 Minute

 0 Likes

 179 Views

When is this applicable?

You’ll probably want to fetch the values that users pass through the various InputElements or other types of Elements (like infographics, plots, or tables). This article will show how to fetch the values from these elements so that you can leverage the interactive nature of the platform. 

 

How-To

The type of value(s) stored in an element and how to access it is dependent on the Element class.  For each of the Element subclasses, the following are methods to retrieve their fundamental values (although there is usually subclass-specific metadata and parameters stored in their instances as well):

  • InputElement[Element]: elem.content
    • Dropdown[InputElement]: elem.selected
    • NumericRange[InputElement]: elem.min_selection, elem.max_selection
    • DateTimeRange[InputElement]: elem.min_selection, elem.max_selection
    • TextInput[InputElement]: elem.value
    • DataSource[InputElement]: elem.value
  • Dashboard[Element]: elem.content (the list of subelements)
  • Image[Element]: elem.content (Pillow image)
  • Infographic[Element]: elem.data (the list of InfographicData)
  • Plot[Element]: elem.data (the list of PlotDataPoints)
  • Table[Element]: elem.content (the dataset)

 

Example

In this example, we will procure a DataSource uploaded by a user in a previous step.

pandas, numpy, and the StoreInterface class from the predict-backend module will already need to have been imported at the start of your flow file. 

First, we instantiate an instance of the class while passing in the **flow_metadata variable-length argument.  From here we can call the get_element_value method on our class instance while passing in the two following parameters:

  • The name of the step object in which the user uploaded the DataSource
  • The name given to DataSource in the aforementioned step

This will return a pandas.DataFrame containing the data uploaded by the user.

from predict_backend.store.store_interface import StoreInterface
import numpy
import pandas

#########################

# Get store_interface
store_interface = StoreInterface(**flow_metadata)

# Fetch input data
data = store_interface.get_element_value(data_upload_step.name, "S&P 500 Dataset")

 

What to Expect (Validation)

The data you’ve fetched will be available in whatever variable you store it in and can subsequently be used to manipulate that data further. 

 

Additional Details

The base Element class does have methods to get metadata about the Element instance such as the title, description, id, and other configuration parameters. These can be accessed as members of the instance and also serialized with to_json() and saved as a json as save()

Was this article helpful?