Oh I completely missed that part of the error, but indeed, as Matthijs points out you can’t call the compute over api from within an app.
Not sure what you are trying to build, but i can imagine it’s something like having a parent and a child entity, and that you want to perform a batch calculation of all the child entities, correct?
If so, that is possible to do from within an app, and you don’ t even need the compute-over-API.
Say you have a child entity with a calculation of some sort, e.g.:
class Controller(vkt.Controller):
label = 'My Entity Type'
parametrization = Parametrization
@vkt.TableView("Student Grades")
def table_view(self, params, **kwargs):
data = [
["John", 6.9],
["Jane", 8.1],
["Mike", 7.5],
]
return vkt.TableResult(data, column_headers=[
"Name",
vkt.TableHeader("Grade", num_decimals=0)
])
You could write a method on your parent entity to loop over all children and call that tablemethod. In this example I dump those results into a file but of course you can use the results any way you want. In the parent entity you can do this by importing the childentity controller, and then calling in a loop over all children like this:
import viktor as vkt
from ..my_entity_type.controller import Controller as ChildEntityType
class Parametrization(vkt.Parametrization):
btn = vkt.DownloadButton('Click to download child table results', method='download_child_results')
class Controller(vkt.Controller):
label = 'My Folder'
children = ['MyEntityType']
show_children_as = 'Table'
parametrization = Parametrization
def download_child_results(self, params, entity_id, **kwargs):
api = vkt.api_v1.API()
entity = api.get_entity(entity_id)
zipped_file_dict = {}
for child in entity.children():
table_result = ChildEntityType().table_view(ChildEntityType(), params=child.last_saved_params)
# Extract data from child result and store it in a file in the dict
zipped_file_dict[f'{child.name}.txt'] = vkt.File.from_data(str(table_result.data))
return vkt.DownloadResult(zipped_files=zipped_file_dict, file_name="all_child_tables.zip")
It looks a bit different, but we import ChildEntityType
, and then call it in the loop by creating it and accessing the table_view
which takes self
(hence we give ChildEntityType()
as the first argument) and then the params.
Hope that helps!