bokeh tabs does not clear for subsequent figure - bokeh

I'm not sure I can provide enough context here but I think so.
I'm running a bokeh server to generate a few plots and in a Flask app put them on a page, like this
script1 = bokeh.embed.server_document(...)
script2 = bokeh.embed.server_document(...)
...
return render_template(..., script1=script1, script2=script2)
On the template each plot is wrapped in a div with line breaks, paragraph breaks, and so on:
<style>
.gap-20 {
width:100%;
display: block;
}
</style>
<p>
<h3>Anchors and their inferences</h3>
<br />
<div class="gap-20">
{{ script1 | safe }}
</div>
</p>
<p>
<h3>Reproduction of forward data</h3>
<br />
<div class="gap-20">
{{ script2 | safe }}
</div>
</p>
The plots that mess up layout on the page are those containing 'Panel' and 'Tabs'. Other plots are fine. See image for the problem.
The problem is: the plot using 'Tabs' does not clear, so that the capture of the next plot, "Reproduction of forward data", appears to the right of the figure on the active tab, just below the tab titles, although I have plenty of and before "Reproduction of forward data".
The code for 'script1' is like this on the Bokeh server side:
from bokeh.plotting import figure
from bokeh.models import Slider, Panel, Tabs
from bokeh.layouts import column
f1 = figure(...)
s1 = Slider(...)
fig1 = column(s1, f1)
f2 = figure(...)
s2 = Slider(...)
fig2 = column(s2, f2)
tab1 = Panel(child=fig1, ...)
tab2 = Panel(child=fig2, ...)
tabs = Tabs(tabs=[tab1, tab2])
doc.add_root(tabs)
A puzzling part is that this used to work a few weeks ago, back then 'tabs' is wrapped in 'column', like 'doc.add_root(column(tabs))'. Days ago I upgraded Bokeh to the latest 0.12.13, the issue above appeared. With or without 'column', the issue is the same. I'm not totally sure Bokeh upgrade is the cause but it's very likely so.
So the question is, what needs to be done around this 'Tabs' or 'Panel' to fix this problem? Thanks.

New findings: with Bokeh 0.12.10, with Tabs wrapped in row or column, that is,
doc.add_root(row(tabs))
or
doc.add_root(column(tabs))
things work as expected. The next plot comes cleanly below the first. If Tabs are passed to doc.add_root w/o row or column, the problem described in the post and shown in the picture occurs.
Now upgrade to Bokeh 0.12.11, w/o row or column around Tabs, same problem as shown in the original question post (and the same as with Bokeh 0.12.10). With row or column, things are messier:
The two figures seem to be vertically collapsed. This bug continues through the latest version, 0.12.13.

Related

Coldfusion: CFChart format labels on horizontal bar graph

I am having trouble aligning Horizontal Bar graph x-axis Labels, I have long names that I have wrapped using /n. The labels are no longer right aligned (see picture). Is there a way to left or right align (see image)?
I am new creating charts in CF and am stumbling around, if anyone can point me to any documentation that will allow me to know what are valid attributes are for elemets (ie: xAxis...itemsOverlap), I stumbled on this from a post but don't know where to find this info, thanks.
While I am here is there any way to change the color of the value displayed for each bar? (or have that number appear inside the bar?).
again thank for your patients as I am new to this.
<CFSET xAxis_disp = {"itemsOverlap":true, "max-items": SQL_Query.RecordCount}>
<CFSET aspect3d_small={"angle":0,"depth":7,"true3d":false}>`
<CFSET yAxisStep_25 = {"min-value":"0","step":"5"}>
<CFCHART
style="default"
show3d="yes"
chartHeight="#chartHeight_error#"
chartwidth="500"
type="horizontalbar"
gridlines="20"
yAxis = "#yAxisStep_25#"
xAxis="#xAxis_disp#"
aspect3d="#aspect3d_small#"
font="times" >
<CFCHARTSERIES
colorlist="##234086,##284A99,##284A99,##325CC0,##3D68CD,##5077D2,##6486D7,##7795DC,##8BA4E1"
query="SQL_Query"
type="bar"
datalabelstyle="value"
itemcolumn="CRFNAME"
valuecolumn="ErrCounter">
</CFCHARTSERIES>
</CFCHART>
Chart Labels, not aligned
FWIW, CFChart is just a wrapper around ZingChart, so the ZingCharts docs will be more helpful for stuff like this. I usually end up googling "How to do [X] with ZingChart" and/or pore over the ZingChart docs to find the syntax ... then figure out how it maps to the CF attributes with a little trial and error :-).
Anyway, the xAxis item alignment is controlled with "item": { "text-align":"right"}. Add it to your xAxis_disp structure. For the other xAxis attributes (i.e. "Scale-X"), have a look at the ZingChart docs
<CFSET xAxis_disp = {"items-overlap":true
, "max-items": 6
, "auto-fit": true
, "item": { "text-align":"right"}
}>
Runnable TryCF.com Example

Bokeh MultiLine p.add_tools(HoverTool(), renderers = [multiline]) not working

So when trying to add a HoverTool to a plot, the MultiLine Hover works.
But the problem I am having is, that I have another highlighting Single Line, that I do not want the Hover to act on.
So I wanted to input just the multiline to the renderers keyword
p.add_tools(HoverTool(tooltips = [('Name: ', '#Name'),
('Value', '#Value')],
renderers = [multiline]
)
and I am getting the following error:
ValueError: expected an element of either Auto or List(Instance(Renderer)), got [MultiLine(id='4982e76f-7dda-4d78-b729-240c9a29bdef', ...)]
What am I missing?
Glyphs (such as MultiLine) are more like a description of what to draw. There is a seperate GlyphRenderer that takes glyphs and uses them to draw (it can actually have several versions of a glyph to use in different cases, e.g. for selecting and highlighting and decimating). The renderers arg of the hover tool expects the GlyphRenderer, not the glyph.
If you are using bokeh.plotting, then the glyph renderer is returned by the method on the figure:
r = plot.multi_line(...) # r is what to configure on the hover tool
If you are using the low level bokeh.models API then you must already be configuring a GlyphRenderer manually for your MultiLine. Pass that to the hover tool instead.

Updating gWidgets elements in R

I'm having trouble updating graphical elements in R and I can't figure it out. I'd appreciate a little push.
I'm trying to make a simple GUI which is prepopulated with some options, but when a button is pressed the database is queried (the query is modified by the GUI), and the result needs to change what's available in the gcomboboxes and gtables. I'm frankly amazed at how simple it is to create such an excellent environment in R.
I don't believe I can modify the body of gcomboboxes or gtables once they're on screen (if I can, that's probably my preferred solution). I also don't believe I can destroy individual elements of a glayout, only the entire glayout. But how do I get it back in the right order?
# Small example for GUI element creation and destruction
if(!require("RGtk2")) {library("RGtk2")}
if(!require("digest")) {library("digest")}
if(!require("cairoDevice")) {library("cairoDevice")}
if(!require("gWidgets")) {library("gWidgets")}
if(!require("gWidgetsRGtk2")) {library("gWidgetsRGtk2")}
nw<-gwindow("Test",toolkit=guiToolkit("RGtk2"))
g<-ggroup(horizontal=FALSE,cont=nw)
t1<-glayout(container=g) # Header
t2<-glayout(container=g) # Dynamic middle
t3<-glayout(container=g) # Footer
t1[1,1]<-gcombobox(c("foo","bar"))
t1[1,2]<-gbutton("Update")
t2[1,1]<-gframe("",container=t2)
t2[2,1]<-gcombobox(c("violin","metal"))
t2[3,1]<-gtable(c("YoYoMa","Metallica"))
t3[1,1]<-glabel("Filler text",container=t3)
delete(g,t2) # Unable to delete t2[2,1] and t2[3,1]
t2<-glayout(container=g)
#t2[2,1]<-gcombobox(c("violin","metal","pop")) ### Nope...
#t2[3,1]<-gtable(c("YoYoMa","Metallica","UB40"))
#add(t2,gcombobox(c("violin","metal","pop"))) ### Nope...
#add(t2,gtable(c("YoYoMa","Metallica","UB40")))
All my added elements go below my footer text. How do I straighten it out so they go between the header and footer?
If I don't delete the glayout, it looks like I can modify the contents of the gcombobox, but the UI doesn't really reflect it. I can see new text when I click the arrow, but the selection no longer appears to change.
...
t2[2,1]<-gcombobox(c("text to remove","violin","metal"))
t2[3,1]<-gtable(c("YoYoMa","Metallica"))
t3[1,1]<-glabel("Filler text",container=t3)
t2[2,1]<-gcombobox(c("violin","metal","pop")) # "text to remove" remains selected regardless of user input
t2[3,1]<-gtable(c("YoYoMa","Metallica","UB40"))
It was a little frustrating, but this is working well for me. I'll leave this solution here in case anybody else has trouble.
# Small example for GUI element creation and destruction
if(!require("RGtk2")) {library("RGtk2")}
if(!require("digest")) {library("digest")}
if(!require("cairoDevice")) {library("cairoDevice")}
if(!require("gWidgets")) {library("gWidgets")}
if(!require("gWidgetsRGtk2")) {library("gWidgetsRGtk2")}
nw<-gwindow("Test",toolkit=guiToolkit("RGtk2"))
g<-ggroup(horizontal=FALSE,cont=nw)
t1<-glayout(container=g) # Header
t2<-glayout(container=g) # Dynamic middle
t3<-glayout(container=g) # Footer
t1[1,1]<-gcombobox(c("foo","bar"))
t1[1,2]<-gbutton("Update")
t2[1,1]<-gframe("",container=t2)
t2[2,1]<-gcombobox(c("text to remove","violin","metal"))
t2[3,1]<-gtable(c("YoYoMa","Metallica"))
t2[3,1]<-gtable(BandList)
t3[1,1]<-glabel("Filler text",container=t3)
t2[2,1][]<-c("violin","metal","pop")
svalue(t2[2,1])<-"pop" #otherwise it's confused about defaults
t2[3,1][]<-c("YoYoMa","Metallica","UB40")
I found a way to edit the contents already on screen without needing to delete the screen elements.
# Small example for GUI element creation and destruction
if(!require("RGtk2")) {library("RGtk2")}
if(!require("digest")) {library("digest")}
if(!require("cairoDevice")) {library("cairoDevice")}
if(!require("gWidgets")) {library("gWidgets")}
if(!require("gWidgetsRGtk2")) {library("gWidgetsRGtk2")}
nw<-gwindow("Test",toolkit=guiToolkit("RGtk2"))
g<-ggroup(horizontal=FALSE,cont=nw)
t1<-glayout(container=g) # Header
t2<-glayout(container=g) # Dynamic middle
t3<-glayout(container=g) # Footer
t1[1,1]<-gcombobox(c("foo","bar"))
t1[1,2]<-gbutton("Update")
t2[1,1]<-gframe("",container=t2)
t2[2,1]<-gcombobox(c("text to remove","violin","metal"))
t2[3,1]<-gtable(c("YoYoMa","Metallica"))
t2[3,1]<-gtable(BandList)
t3[1,1]<-glabel("Filler text",container=t3)
t2[2,1][]<-c("violin","metal","pop")
svalue(t2[2,1])<-"pop" #otherwise it's confused about defaults
t2[3,1][]<-c("YoYoMa","Metallica","UB40")

Console not showing up on Xcode Playground 7.1.1

This is what Standard Editor looks like:
This is what Assistant Editor looks like:
This is a problem because whether I click on the eye icon or the + next to (6 times), it shows me a graph only: I was wondering if there would be a way to show more useful output?
Edit: When I show the debug area, it doesn't show any output there:
You can access the console by the menu
View > Debug Area > Show Debug Area
There's also a little upper arrow icon in the bottom left of the Playground, and the SHIFT+CMD+Y shortcut.
In the console you will be able to see not only the error messages but also anything you print.
To be able to see the output in the preview panel you have to place the statement you want to see on a separate line, and break down the logic on separate lines up to some point.
In your case, for example:
let arr = [1,2,3,4,5]
let triple = arr.map({
(i:Int) -> Int in
return i*3
})
Here with let triple ... not being on the same line as the closure anymore, the Playground is able to preview it.
And by clicking on the + on the right side, you can now unfold the special panel where all values are visible:

In Tkinter how do def work?

I made a Tkinter book on a grid, the navergation buttons scroll down the left row and the photos are displayed on the right column spaning many rows so buttons display as they should. When making this Tkinter book.
I made a button on a grid
left1 = Button(win, text=" Captian Scarlet ")# win, is root master
left1.configure(command=but1)# but1 is my first def
left1.grid(row=1, column=0)# all the buttons are on the left list
This displays and works like a button without a def
Then I made a def
def but1():
img = Image.open("captain_scarlett.gif")# loads the gif file
intro = ImageTk.PhotoImage(img)# loads image drivers I belevie
right1 = Label(win, image=intro)# I think Lable is used the same as html <span>
right1.grid(row=0, column=1, rowspan=13)# image formatting to display correctly with buttons
Because I had a lack of education at the time, I could only get the image to displaplay outside a def. So in frustration I posted
"this code works purfect when not put into a def".
When I settled down I needed knowledge that I couldn't find online so I asked the question:
So How do I get this code to work inside a def ?
What makes you think it doesn't work? There's nothing special about Tkinter in this regard; anything that works outside a def definitely works inside a def. The only caveats are the same for all python code. For example, any variables you create inside the def are local unless declared otherwise, and objects (but not widgets) may get garbage collected after the def executes.
Probably what is happening is that you're creating the image and storing a reference to it in a local variable. When the def stops executing the image object is garbage collected. You'll need to keep a reference to the image that can persist. One simple solution might be to do right1.image=intro.
This code works purfecty. Now my production can go full steam ahead
Here is the finished code
def but1():
img = Image.open("captain_scarlett.gif")
intro = ImageTk.PhotoImage(img)
right = Label(win, image=intro)
right.grid(row=0, column=1, rowspan=14)
right.image=intro

Resources