Pytrends & google oauth2

Hi, I just wanted to try to implement “pytrends” i.e. Google Trends in my Streamlit App, but I get the following error:
‘’'Successfully installed lxml-4.6.1 pytrends-4.7.3

Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?client_id…’’’

Why is that? Because when I try to do it locally in my Jupyter notebook, I don’t have to provide login information/credentials or anything like that, as it is the case with other APIs.
Is it possible to fix the problem?

Thanks a lot!

Were you able to figure out how to use pytrends with streamlit?

Hi @namet, welcome to the Streamlit community!! :wave: :partying_face:

Could you go into more detail about the obstacles you face with using pytrends in a Streamlit app? A screenshot would help too!

I was able to use pytrends in a Streamlit app to retrieve trends for a given keyword. Wasn’t able to repro the oauth issue. Here’s the sample code and what the app looks like:

import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt

from pytrends.request import TrendReq

# get google trends data from keyword list
@st.cache
def get_data(keyword):
    keyword = [keyword]
    pytrend = TrendReq()
    pytrend.build_payload(kw_list=keyword)
    df = pytrend.interest_over_time()
    df.drop(columns=['isPartial'], inplace=True)
    df.reset_index(inplace=True)
    df.columns = ["ds", "y"]
    return df

# sidebar
st.sidebar.write("## Trend based on keyword")
keyword = st.sidebar.text_input("Enter a keyword", help="Look up on Google Trends")

if keyword:
    df = get_data(keyword)
    st.dataframe(df)
    fig, ax = plt.subplots()
    ax = df['y'].plot()
    st.pyplot(fig)

Output:

pytrends

Happy Streamlit-ing! :balloon:
Snehan

1 Like

Hi, thanks that helps a lot. Will I be able to share my streamlit app so it is runs locally on others’ machines without any code to launch the app? I want to make sure streamlit has all of the functionality I need before I continue working with it.

Hi @namet, could you expand on what you mean by:

runs locally on others’ machines without any code to launch the app

Once you deploy your app on Streamlit sharing or a cloud provider, you can share the URL of the app with your users. Your users can open the link and directly interact with the app in their web browsers, without having to run any code nor install any additional software on their machines :slight_smile:

Best, :balloon:
Snehan