Why Bokeh has the following error msg? - html

I am trying to follow along the udemy tutorial and ran into the following error:
Bokeh Error
attempted to retrieve property value for property without value specification in the html by running the code below.
Does anyone have a clue as why it happened? Thanks!!
from bokeh.plotting import figure
from bokeh.io import output_file, show, gridplot
#from bokeh.sampledata.periodic_table import elements
from bokeh.models import Range1d, PanTool, ResetTool, HoverTool,
ColumnDataSource, LabelSet
import pandas
from bokeh.models.annotations import Span#assess object within
annotations
#prepare the output file
output_file("layout.html")
x1,y1=list(range(0,10)),list(range(10,20))
#create a new plot
f1=figure(width=250, plot_height=250, title="Circles")
f1.circle(x1, y1, size=10, color="navy", alpha=0.5)
#create a span annotation (a vertical reference line)
span_4=Span(location=4,dimension='height',line_color='grenn',
line_width=2)
#define where to add the span_4 object instance, add_layout method
f1.add_layout(span_4)
#create a box annotation
box_2_6=BoxAnnotation(left=2,right=6,fill_color="firebrick",
fill_alpha=0.3)
f1.add_layout(box_2_6)
#show the results
show(f1)

It appears to be because of a typo - line_color='grenn' should be line_color='green'. You're right that it's an unhelpful error message though. I'll try to open a GH issue about it.

Related

I am trying to Plot using Panels Widget FileInput?

I am trying to make a plotting system with a panel widget FileInput to also read yaml files. I get my buttons to functions and pick my files, but when I try to plot my files I get a TypeError: float() argument must be a string or a number, not 'FileInput'. I am put a sample of my code but not the files I am using on here. I could really use some help in what I am doing wrong. I am just starting to learn python widgets. Thanks in advance for any help I can get.
import matplotlib.pyplot as plt
import panel as pn
pn.extension()
year = 2006
model_path = pn.widgets.FileInput(multiple = True)
model_path
plot_control_file = pn.widgets.FileInput()
plot_control_file
plt.plot(model_path, plot_control_file)

Can we have multiple dashboards of different dropdowns in python dash?

Recently I started using dash for Data Visualization and I'm analyzing the Stock Data using qunadle API, but unable to get multiple dashboards of dropdown displaying the options of each dataset using a for loop like this
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
import quandl
import plotly.graph_objs as go
import auth
api_key = auth.key
def easy_analysis(quandl_datasets):
try:
for dataset in quandl_datasets:
df = quandl.get(dataset,authtoken=api_key)
df = df.reset_index()
app = dash.Dash(__name__)
app.layout = html.Div([
html.H3(dataset),
dcc.Dropdown(
id=dataset,
options=[{'label' : s,'value' : s} for s in df.columns[1:]],
value=['Open'],
multi=True
),
dcc.Graph(id='dataset' + str(dataset))
])
#app.callback(
Output('dataset' + str(dataset),'figure'),
[Input(dataset,'value')]
)
def draw_graph(dataset):
graphs = []
for column in dataset:
graphs.append(go.Scatter(
x=list(df.Date),
y=list(df[column]),
name=str(column),
mode='lines'
))
return {'data' : graphs}
app.run_server(debug=True)
except Exception as e:
print(str(e))
easy_analysis(['NSE/KOTAKNIFTY','NSE/ZENSARTECH','NSE/BSLGOLDETF'])
The Output which I expected was having multiple dashboards with all the dropdown options one after the other. But the result what I got was having only one dashboard of the last item in the easy_analysis() function list
easy_analysis(['NSE/KOTAKNIFTY','NSE/ZENSARTECH','NSE/BSLGOLDETF']), considered only 'NSE/BSLGOLDETF'
what am I supposed do to fix this and get multiple dashboards of each dataset as provided in the list. I also checked the Dash User Guide, but could not get what I was looking for.
But, when passed only one argument for only one dataset with a for loop, the code works fine and the graph changes according to the option selected in the dropdown.
The code is here.
The code does not work because you are redefining a Dash app at each iteration of the for loop.
Even if you have three datasets, you need to define the Dash app and its layout only once.
You can make three requests to the Quandl API and - if possible - save everything in the same pandas Dataframe.
One question is whether you want to display all dropdowns and graphs (i.e. dropdown + graph for each Quandl dataset) or only one dropdown and one graph. I would suggest to start with the first approach, because it's much easier. Anyway, for the second approach you can have a look at this solution.

import 'module' as mod not working

I have a simple import statement:
import './dataMapper' as dataMap;
I am getting an error
Module build failed: SyntaxError: data.jsx: Unexpected token (1:22)
I can't seem to figure out why. If I just plain import without "as ...", it works.
According to at least this:
http://www.sitepoint.com/understanding-es6-modules/
it is the correct syntax.
It's not the correct syntax (and it's not on the page you linked either). You'll want to have a look at http://www.2ality.com/2014/09/es6-modules-final.html for a good reference.
Your code should be
import dataMap from './dataMapper'; // to import the default
or
import * as dataMap from './dataMapper'; // to import the module object

Unable to import react-native-vector-icons using es6

I'm trying to use react-native-vector-icons with ES6 in React Native, but unfortunately I'm having trouble importing the icons. Their documentation still uses the old require statement, so I don't think it's helpful.
This is my import:
import {Ionicons} from './node_modules/react-native-vector-icons/Ionicons.js';
This is my usage:
<Ionicons name="ios-book" color="#4F8EF7" />
The error I receive is:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
It's clear that Ionicons is undefined, so I'm aware that fundamental about the import statement is wrong.
import Ionicons from 'react-native-vector-icons/Ionicons';
import {x} from 'abc'; translates to var x=require('abc').x, not to var x=require('abc').
So what about :
import * as Ionicons from './node_modules/react-native-vector-icons/Ionicons.js';
I ended up using an import statement as follows:
import {default as Icon} from '../node_modules/react-native-vector-icons/Ionicons';
This is because after I followed #Olivier's advice, I ended up with an object that contained a number of properties and I couldn't just use <Icon> as a component, but I discovered that <Icon.default> worked.
Thanks to all who answered!

how do I get ipython to raise warnings everytime (repeated warnings) ?

I would like to import a module, use a function of that module and get a warning message every time the event that triggers the warning happens, not just the first time.
For example if I do (within ipython):
import scipy as sp
import matplotlib.pyplot as plt
x = sp.linspace(0,10)
plt.plot(x,1j*x)
I get the following warning:
/usr/lib/python2.7/dist-packages/numpy/core/numeric.py:320: ComplexWarning: Casting complex values to real discards the imaginary part return array(a, dtype, copy=False, order=order)
however, if I do
plt.plot(x,1j*x)
again, I don't get a warning message. As I said above, I would like to receive a warning message every time, not just the first time.
Thanks in advance.
I figured it out. Add
import warnings
warnings.filterwarnings('always')
before calling
plt.plot(x, 1j*x)