anshul
May 19, 2020, 10:23am
1
I am trying to create a regression line using Altair and Streamlit and I am getting the following error while trying to execute the same:
Duplicate signal name: “selector080_Fiscal_Week”
Below is the code I am using:
import streamlit as st
import pandas as pd
import numpy as np
import altair as alt
def scatter_chart(f, col1, col2):
scatter = alt.Chart(f).mark_point().encode(
x=col1,
y=col2,
tooltip=[col1, col2]).interactive()
reg = scatter.transform_regression(col1,col2).mark_line()
return scatter + reg
st.altair_chart(scatter_chart(df, scatter_opt1, scatter_opt2), use_container_width = True)
Please let me know the issue and how to resolve it ?
Hi @anshul and welcome to the forums !
The interactive() part should be on the concatenated chart :
import streamlit as st
import pandas as pd
import numpy as np
import altair as alt
from vega_datasets import data
df = data.iris()
def scatter_chart(f, col1, col2):
scatter = alt.Chart(f).mark_point().encode(
x=col1,
y=col2,
tooltip=[col1, col2]
)
reg = scatter.transform_regression(col1,col2).mark_line()
return (scatter + reg).interactive() # <--- here
st.write(df)
st.altair_chart(scatter_chart(df, 'sepalLength', 'sepalWidth'), use_container_width = True)
it can also be on the reg definition but it’s clearer to make all of the chart interactive by putting it on the upmost definition
Thanks a lot andfanilo. It works.