# Callback error updating image

**URL:** https://community.plotly.com/t/callback-error-updating-image/60287
**Category:** Dash Python
**Tags:** question
**Created:** [January 21, 2022, 12:02am UTC](https://community.plotly.com/t/callback-error-updating-image/60287 "2022-01-21T00:02:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![iromi](https://avatars.discourse-cdn.com/v4/letter/i/fbc32d/32.png) [@iromi](https://community.plotly.com/u/iromi)
#### Post date: [January 21, 2022, 12:02am UTC](https://community.plotly.com/t/callback-error-updating-image/60287/1 "2022-01-21T00:02:43Z")

</div>

Hi all,

I have mat files containing data of the PET/CT scans. I use an upload function to load mat files. Then based on the user inputted threshold values function suppose to create a figure and should display the figure using graph. Please note that all the images are as nd array. I tried almost all the methods and I am kind of new to dash.

My original layout worked like this:

```auto
html.Div(
                                [

                                    dcc.Graph(
                                        id="image-display-graph",
                                        figure=fig

                                    )
                                ],
                                style={
                                    "grid-column": "1",
                                    "grid-row": "2",
                                    "background-color": DISPLAY_BG_COLOR,
                                },
                            ),

```

And the callback I was doing:

```auto

@app.callback(

    Output('image-display-graph', 'figure'),
    Input('btn_clicks', 'n_clicks'),
    State('hut', 'value'),
    State('suvt', 'value'),
    State('upload_file', 'filename')

)

```

And the function to get the segmented figure I was doing:

```auto
def make_seg_image(filename, hu, suvt, btn_clicks):
    data = read_mat(os.path.join('D:\data', filename))
    if 'pt_image' in data:
        ct_image = data['ct_image']
        pt_image = data['pt_image']

        mid_slice_pt = np.round(np.array(pt_image.shape) / 2).astype(int)
        pt_slice = pt_image[:, :, mid_slice_pt[2]]

        mid_slice_ct = np.round(np.array(ct_image.shape) / 2).astype(int)
        ct_slice = ct_image[:, :, mid_slice_ct[2]]

        # ct_segmentation
        threshold_ct_img = ct_slice > hu
        # Apply PET image to CT bone mask
        pet_mask = np.multiply(pt_slice, threshold_ct_img)

        pt_image_suvt = pet_mask > suvt
        fig = px.imshow(pt_image_suvt, animation_frame=0, facet_col=1, binary_string=True)

        return fig

```

But I am continuously getting callback errors

---

<div class="post-metadata">

### Author: ![Eduardo](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/eduardo/32/13310_2.png) [@Eduardo](https://community.plotly.com/u/Eduardo)
#### Post date: [January 21, 2022, 10:18am UTC](https://community.plotly.com/t/callback-error-updating-image/60287/2 "2022-01-21T10:18:45Z")

</div>

Hi @iromi

Add the ERROR message to understand where the problem is.

---

<div class="post-metadata">

### Author: ![iromi](https://avatars.discourse-cdn.com/v4/letter/i/fbc32d/32.png) [@iromi](https://community.plotly.com/u/iromi)
#### Post date: [January 21, 2022, 11:44am UTC](https://community.plotly.com/t/callback-error-updating-image/60287/3 "2022-01-21T11:44:51Z")

</div>

Hi, I got this error

**Callback error updating image-display-graph.figure**

**TypeError: join() argument must be str, bytes, or os.PathLike object, not 'int’**

**## Traceback _(most recent call last)_**

\*\*\* #### File “C:\Users\Iromi\anaconda3\envs\tensorflow\_GPU\Lib\ntpath.py”, line _91_ , in `join`\*\*

**for p in map(os.fspath, paths):**

\*\*\* During handling of the above exception, another exception occurred:\*\*

\*\*\* #### File “C:\Users\Iromi\anaconda3\envs\tensorflow\_GPU\Lib\genericpath.py”, line _152_ , in `_check_arg_types`\*\*

**raise TypeError(f’{funcname}() argument must be str, bytes, or '**

**\> TypeError: join() argument must be str, bytes, or os.PathLike object, not 'int’**

**Traceback (most recent call last):**  
\*\* File “C:\Users\Iromi\anaconda3\envs\tensorflow\_GPU\Lib\ntpath.py”, line 91, in join\*\*  
\*\* for p in map(os.fspath, paths):\*\*  
**TypeError: expected str, bytes or os.PathLike object, not int**

**During handling of the above exception, another exception occurred:**

**Traceback (most recent call last):**  
\*\* File “C:\Users\Iromi\anaconda3\envs\tensorflow\_GPU\Lib\genericpath.py”, line 152, in \_check\_arg\_types\*\*  
\*\* raise TypeError(f’{funcname}() argument must be str, bytes, or '\*\*  
**TypeError: join() argument must be str, bytes, or os.PathLike object, not 'int’**

Thanks

---

<div class="post-metadata">

### Author: ![jlfsjunior](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jlfsjunior/32/16061_2.png) [@jlfsjunior](https://community.plotly.com/u/jlfsjunior)
#### Post date: [January 21, 2022, 12:12pm UTC](https://community.plotly.com/t/callback-error-updating-image/60287/4 "2022-01-21T12:12:04Z")

</div>

Hi,

If `make_seg_image` is your callback, then the arguments order is wrong and `filename` is the click counter (that’s why `os.path.join` is complaining about an int type).

The signature should be `make_seg_image(btn_clicks, hu, suvt, filename)`.

---

<div class="post-metadata">

### Author: ![iromi](https://avatars.discourse-cdn.com/v4/letter/i/fbc32d/32.png) [@iromi](https://community.plotly.com/u/iromi)
#### Post date: [January 21, 2022, 1:05pm UTC](https://community.plotly.com/t/callback-error-updating-image/60287/5 "2022-01-21T13:05:21Z")

</div>

Hi,

Thanks for the reply. I make it correct. Now there are no errors. But still, the image is not showing.

Thanks
