Error when importing Input

Hello!
When importing Input from the Dash library in python (from dash import Input) I am getting the following error:

ImportError: cannot import name 'Input' from 'dash' 

I made sure I have the newest version of Dash installed.

Thanks in advance,
YW

Hi yaniv_w

How you import your libraries?. Here is a example.

https://dash.plotly.com/basic-callbacks

from dash import Dash, dcc, html, Input, Output

app = Dash(__name__)

app.layout = html.Div([
    html.H6("Change the value in the text box to see callbacks in action!"),
    html.Div([
        "Input: ",
        dcc.Input(id='my-input', value='initial value', type='text')
    ]),
    html.Br(),
    html.Div(id='my-output'),

])


@app.callback(
    Output(component_id='my-output', component_property='children'),
    Input(component_id='my-input', component_property='value')
)
def update_output_div(input_value):
    return f'Output: {input_value}'


if __name__ == '__main__':
    app.run_server(debug=True)

image

hey @SamuelVT ,
thans for the quick replay!
I am importing the library in the common way:

from dash import Input

with no further lines besides this one, when I run it I get that error.

Hi yaniv_w

  • Check your version against the latest versions announced in this forum or in the CHANGELOG. If you are on an older version, try upgrading.

  • You can find these versions by doing: print(dash.__version__) , print(dcc.__version__) , print(html.__version__) , print(dash_table.__version__) , print(plotly.__version__)

HI @SamuelVT

on one hand, when I run the print lines in this order, I get this output:
1.17.0
1.13.0
1.1.1
4.11.0
5.6.0

meaning that my notebook uses dash version 1.17.0
on the other hand, I have the version 2.0.1 installed.
how come?

Hi yaniv_w

Plotly with Jupyter Notebook for Windows

  • Open command prompt and cd into your main directory
  • Create directory where you want to develop your project/app, by typing: mkdir foldername
  • cd into the new folder
  • Create a virtual environment, by typing: py -m venv EnvironmentName
  • Activate your new environment, by typing: .\EnvironmentName\Scripts\activate
  • Install required libraries into activated virtual environment:
        pip install pandas
        pip install dash
        pip install notebook
  • Check the full list of libraries you just installed, by typing: pip list

dash 2.1.0
dash-core-components 2.0.0
pandas 1.3.5
etc…

Start Jupyterlab by typing: jupyter notebook

  • Run your app

Here is a example:

from dash import Dash, dcc, html, Input, Output

app = Dash(__name__)

app.layout = html.Div([
    html.H6("Change the value in the text box to see callbacks in action!"),
    html.Div([
        "Input: ",
        dcc.Input(id='my-input', value='initial value', type='text')
    ]),
    html.Br(),
    html.Div(id='my-output'),

])


@app.callback(
    Output(component_id='my-output', component_property='children'),
    Input(component_id='my-input', component_property='value')
)
def update_output_div(input_value):
    return f'Output: {input_value}'


if __name__ == '__main__':
    app.run_server(debug=False, use_reloader=False) 
3 Likes

Hello Samuel :
I have a similar issue I want to use

that uses CTX
but the first step itself creating error being

cannot import name ‘ctx’ from ‘dash’ ( I am using Anacond + Ubuntu os)
any suggestion, I have no help in google search itself .

Hello @yogi_dhiman,

What version of dash are you using?

Jinny I am using 2.0.0

Dash is now at version 2.6.2, is it possible to update to that version?

yes, I tried that but after update I got additional errors

This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

open to any suggestion

Can’t really say without seeing your dependencies, but to run the code as is, you have to update Dash to a later version.

What you could do is spin up a new virtual environment and install the packages and then see if it runs.

1 Like

Thanks ! for the tip
I did create a new virtual environment + updated dash version … solved the problem .

1 Like