Marih
Marih

Reputation: 1

Size of results returned by TabPy

I am currently building an optimal allocation model using scipy.optimize.linprog python code and need to show the results on Tableau.

For simplicity's sake I will say that I have two tables: A- the supply available of the different Supply Buckets and B- the different recipients and how many objects they have demanded in each Slot.

A =

Object Available
Bucket 1 100
Bucket 2 100

B =

Recipient Object Demanded Slot 1 Slot 2
Recipient 1 Bucket 1 20 30
Recipient 2 Bucket 1 60 50
Recipient 2 Bucket 2 20 10

The optimisation will give as an output, how many objects are coming from each viable Supply Bucket to each Slot of each Recipient, e.g., How many doses will be going from Bucket 1 to Recipient 1 in Slot 1?, then again for Slot 2?

The objective function ends up being of size n (in this case n=6), the number of bounds ends up being of size m (here m=8, 6 of which being how many objects were demanded in each slot and 2 being the limit on supply) and the list of constraints is of size n x m.

In order to make the size of all fiels the same size to use them as TabPY SCRIPT arguments, I unioned both tables and filter accordingly inside the Python Script, giving me columns of size 5. However, TabPy is now expecting a return list also of size 5 now, or that the returned value will then be repeated 5 times and in this case, my desired returned list is of size n=6.

Is there a way of getting TabPy to return a list of different size than what it received? Or do you have any suggestions as to how I can transform my data to make this function work?

Workarounds I have attempted:

  1. I have made the SCRIPT_STR function return my result, formatted as a pandas dataframe, as a string. However this is extremely visually disjointed and difficult to read as so:

screenshot of how string output looks

  1. I have otherwise run the model in Tableau Prep, where the output table is the model result and then used this as my data source in Tableau Desktop. This works just fine, however, I have some parameters on the dashboard that I would like to integrate into my model, which I believe isn't possible if the model is being used in the data flow in Tableau Prep?

Upvotes: 0

Views: 121

Answers (1)

MUFF.
MUFF.

Reputation: 791

Using Tableau Blends

You can import your data from its respective source or tables and then blend them in tableau on [object] and [object_demanded].

Upvotes: 0

Related Questions