How to add range slider or widget on my code

#Im beginner on python plotly and i stuck on this part, whenever i add code from documentation, i got an error.

import pandas as pd
import plotly.express as px
import plotly.graph_objects as go

#load csv file
df = pd.read_csv(‘input_file.csv’)

fig = px.scatter(df, x = ‘datetime’,

             y = ['observed_tide', 'estimated_tide', 'deviation'], 
             color = 'variable',
             labels = {'variable': 'legend', 'datetime': 'Date/Time'})

fig.update_layout (title = ‘Tide Visualization’, font=dict(size=18))

fig.show()

Since your data is unknown, here is the code to add a range slider based on similar data in the plotly reference.

import plotly.express as px

df = px.data.stocks()
fig = px.scatter(df, x="date", y=["GOOG","AAPL","NFLX"])
fig.update_layout(title="Tide Visualization", font=dict(size=18))
fig.update_layout(xaxis=dict(rangeslider=dict(visible=True)))
fig.show()

Thank you but the graph inside the slider is not showing

What are the differences from the data used in the reference? Submit reproducible data first. And what version of Plotly are you using?

Version 6.0.1

CSV FILE

I believe it is due to the number of data counts you are using. See here for more information. If you change the render mode to SVG, the range slider will be enabled, but moving the slider will cause extremely poor performance and use. (Depending on your personal environment.) See here for an explanation of WegGL.

import pandas as pd
import plotly.express as px

df = pd.read_csv('output_file.csv')

fig = px.scatter(df,
                 x='datetime',
                 y=['observed_tide', 'estimated_tide', 'deviation'],
                 color = 'variable',
                 labels = {'variable': 'legend', 'datetime': 'Date/Time'},
                 render_mode='svg', # update
                )

fig.update_layout(title='Tide Visualization', font=dict(size=18))
fig.update_layout(xaxis=dict(rangeslider=dict(visible=True)))

fig.show()