yaniv_w
February 14, 2022, 10:48am
1
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)
yaniv_w
February 16, 2022, 9:31am
3
yaniv_w:
from dash import Input
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.
yaniv_w
February 16, 2022, 10:51am
5
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
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
Here is what would happen if you followed my suggestion:
[image]
Coded (used Aimped for initial):
import dash
from dash import html, Input, Output, callback_context
import numpy as np
import dash_bootstrap_components as dbc
# raw input
cards = ['2s', '3s', '4s', '5s', '6s', '7s', '8s', '9s', 'Ts', 'Js', 'Qs', 'Ks', 'As',
'2h', '3h', '4h', '5h', '6h', '7h', '8h', '9h', 'Th', 'Jh', 'Qh', 'Kh', 'Ah',
'2d', '3d', '4d', '5d', '6d', '7d', '8d', '9d', 'Td', 'Jd', 'Qd', 'Kd', 'Ad'…
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?
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