Problems with JPGAndDataResult

I want to use the JPGAndDataView but giving the imagepath to JPGAndDataResult doesn’t work. How should I retrieve the image from the path to make this work?

    @JPGAndDataView("Gekozen profiel", duration_guess=1)
    def get_chosen_profile(self, params: dict, entity_id: int, **kwargs) -> JPGAndDataResult:
        project_params = self.get_project_params(entity_id)
        selected_section_index = params['design']['visualisation']['visualize_section_options']
        selected_variant = get_variant_with_inputs(params, selected_section_index)=            
        image_path = selected_variant.get_path_to_image()
        
        data = DataGroup(
            DataItem('Data item 1', 123)
        )
        
        return JPGAndDataResult(html=image_path, data=data)

Hello Bob,

I spotted two issues with your snippet:

  1. the image should be of type BytesIO (SDK Reference - Views | VIKTOR Documentation)
  2. JPGAndDataResult does not accept a html argument, this should be image
from io import BytesIO
image = BytesIO()
with open(image_path, 'rb') as f:
    image.write(f.read())
return JPGAndDataResult(image=image, data=data)