Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotly figure always generating with y = [0...n] #763

Open
lz039 opened this issue Jan 31, 2025 · 6 comments
Open

Plotly figure always generating with y = [0...n] #763

lz039 opened this issue Jan 31, 2025 · 6 comments

Comments

@lz039
Copy link

lz039 commented Jan 31, 2025

Hi folks,

the generated SQL and the table / df output is correct, but for plotly generation the y-axis is always only counting upwards:
for x = 0, y = 0,
for x = 1, y = 1
... and so on

Image

I use this default route

@app.route('/api/v0/generate_plotly_figure', methods=['GET'])
@requires_cache(['df', 'question', 'sql'])
def generate_plotly_figure(id: str, df, question, sql):
    try:
        code = vn.generate_plotly_code(question=question, sql=sql, df_metadata=f"Running df.dtypes gives:\n {df.dtypes}")
        fig = vn.get_plotly_figure(plotly_code=code, df=df, dark_mode=False)
        fig_json = fig.to_json()

        cache.set(id=id, field='fig_json', value=fig_json)

        return jsonify(
            {
                "type": "plotly_figure", 
                "id": id,
                "fig": fig_json,
            })
    except Exception as e:
        # Print the stack trace
        import traceback
        traceback.print_exc()

        return jsonify({"type": "error", "error": str(e)})

Can anyone help?

@lz039
Copy link
Author

lz039 commented Jan 31, 2025

Probably I need to update my code as to #733 the vanna-flask repo is outdated.

@lz039
Copy link
Author

lz039 commented Feb 3, 2025

I did the update but still not working.

Even generate_plotly_figure returns the correct plotly configuration, it's not rendered correctly.
If I use the data returned in generate_plotly_figure in a python notebook it looks great, but on the vanna webserver ui the plot is empty, without any error messages.

@SkyCandy567
Copy link

I am running into the same issue. Any resolution yet?

@SkyCandy567
Copy link

It looks like the newer version of plotly may have broken it? I went down to plotly==5.22.0 and now its working. I suspect maybe something to do with fig_json = fig.to_json()

@zainhoda
Copy link
Contributor

zainhoda commented Feb 9, 2025

@SkyCandy567 could you try with the even newer version of Plotly (6.0)?

@stefan22mar
Copy link

Hey did you manage to fix this issue? I'm struggling with this as well and I thought at first it was because of a weird binary encoding the fig.to_json() function does.

It looks something like this:

'y': {'bdata': ('PIw5PL8O7j9nHrgAgw3zP0aQ6rSh3/' ... '8K5gRAB0hi8sLhBUDZtkLgDdIGQA=='),
'dtype': 'f8'},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants