TODAY learn how to bring Drag & Drop to Dash with Dashboard Engine. 🌠 Sign up for the live event!

Secondary y-axes throws an error

I am trying to plot a secondary y-axes and generally follow a fig = go.Figure{data = [], layout = []}.

Traceback:

Exception: In order to reference traces by row and column, you must first use plotly.tools.make_subplots to create the figure with a subplot grid.

## Traceback *(most recent call last)*

* #### File "/Users/kevalshah/opt/anaconda3/lib/python3.7/site-packages/plotly/basedatatypes.py", line *1856* , in `_validate_get_grid_ref`

raise AttributeError("_grid_ref")

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

Code:

# Velocity graph
@app.callback(Output("velocity-graph", "figure"),
              [
                 Input("submarket-select", "value")
                 #Input("bldg-select", "value")
              ],
             )
def update_velocity(submarket):

    if submarket:

        df = df_absorp.loc[(df_absorp["Year"] >= 2010)]

        #df = df_absorp.loc[(df_absorp["Year"] >= '2010') & (df_absorp["Class"] == class)]

        fig = go.Figure(

            data=[

                  go.Bar(
                        x=df["Date_Col"],
                        y=df["NetAbsorptionUnits"],
                        name="Net Absorption"
                        ),

                  ],

            layout=go.Layout(

                title="Market Velocity : Rent Growth, Vacancy and Net Absorption",

                xaxis=dict(
                    tickangle=60,
                    tickfont=dict(family="Rockwell", color="crimson", size=14)
                ),

                yaxis=dict(
                    title="Net Absorption Rate",
                    showticklabels=True
                ),

                barmode="stack",

            )
        )

        fig.add_trace(go.Scatter(
                        x=df["Date_Col"],
                        y=df["VacantPct"],
                        name="Vacancy Rate",
                        marker=dict(color="rgb(204,0,0)")
                        ),
                        secondary_y=False,
        )

        fig.add_trace(go.Scatter(
                        x=df["Date_Col"],
                        y=df["AskingPctChg"],
                        name="Rent Growth",
                        marker=dict(color="rgb(0,153,76)")
                        ),
                        secondary_y=True,
        )

        fig.update_layout(template=plotly_template)

        return fig

    else:

        return (no_update)