Vaibhav Nellore
Vaibhav Nellore

Reputation: 41

Altair chart not showing up in Streamlit with VConcat

I tried to project altair chart using streamlit. My requirement is to project two charts in such a way that if i select few points in the above chart with scattered points i should see the distribution of a variable('notes') in the below chart. For that i have written the below code where i am using vconcat in the function. But, The chart never shows up when i use vconcat. But, It works fine when i try to project single chart.

    def altair_graph(embd_1):
    
        selected = alt.selection_single(on="click", empty="none")
        brush = alt.selection(type='interval')
    
        dom = ['Other IDs', 'Slected ID','Sel Dims']
        rng_clr = ['lightgrey', 'red','blue']
    
        color_point=alt.Color('color', scale=alt.Scale(domain=dom, range=rng_clr))
    
        color = alt.condition(selected, alt.value('red'), color_point,legend=None)
    
        chart = alt.Chart(embd_1).mark_circle(size=30).encode(
            x = 'dimention1:Q', 
            y = 'dimention2:Q',
            tooltip=['ID','notes'] ,
            color=color
            ).properties(width=600,height=600).add_selection(brush).add_selection(selected).interactive()
    
        bars = alt.Chart(embd_1).mark_bar().encode(
                y='notes:N',
                color='notes:N',
                x='count(notes):Q'
                ).transform_filter(brush).interactive()
        
        #final_chart = ((chart & bars))
        final_chart = alt.vconcat(chart,bars)
    
        return final_chart

selected=altair_component(altair_chart=altair_graph(embd_1))

Upvotes: 0

Views: 599

Answers (1)

roble
roble

Reputation: 304

From your snippet I assume that you are using the altair-part of the streamlit-vega-lite custom component. Currently it seems like it is not possible to use the streamlit-vega-lite component to retrieve selections from compound charts.

That said, it is not entirely clear to me, why the chart is not showing at all. And without a minimal reproducible example, we can't test. I had a similar case lately, where it worked to plot the charts both, separately, as well as together as a compound. Also the selections work as such, however, values are not reflected back in the event dict that gets returned from the altair_component

Upvotes: 1

Related Questions