Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Unresolved reference to function scope variable when making an html component to return

    def get_accessions_from_text(btn_search, searchterm):
        """

        :param btn_search:
        :param searchterm:
        :return: html Pre of array of accessions, str query translation
        """
        if btn_search<=0:
            return no_update, no_update
        accessions_arr, query_translation = searchByTerm(searchterm)

        #return A links, click for full GB info
        acc_arr_links = html.Div(
                        children=[
                            html.Ul(children=[
                               html.Li([
                                    id=f'li-{accessions_arr[i]}',
                                    children=[
                                    html.A(accessions_arr[i],
                                           n_clicks=0,
                                           href="#",
                                           id=accessions_arr[i])
                                    ] 
                                ] for i in range(len(accessions_arr)))
                            ])
                        ])

        return acc_arr_links, query_translation

It says "Unresolved reference accessions_arr. How can I fix this to output a list of links of the contents of accessions_arr?

This does not give any syntax errors but won’t output anything.

#return A links, click for full GB info
        acc_arr_links = html.Div(
            html.Ul(
                children=[
                    html.Li(
            html.A(accessions_arr[i],
                   n_clicks=0,
                   href=f"https://www.ncbi.nlm.nih.gov/search/all/?term={accessions_arr[i]}",
                   target="_blank",
                   id=f'link-{accessions_arr[i]}')
                        for i in range(len(accessions_arr)))]
            ))

        return acc_arr_links, query_translation

My ugly solution to use surround P tags:

acc_arr_links = html.Div(
                    children=[
                    html.P(
                    html.A(accessions_arr[i],
                    n_clicks=0,
                    href=f"https://www.ncbi.nlm.nih.gov/search/all/?term={accessions_arr[i]}",
                    target="_blank",
                    id=f'link-{accessions_arr[i]}'))
                        for i in range(len(accessions_arr))])


        return acc_arr_links, query_translation