散景服务器图不更新

时间:2020-02-09 20:14:12

标签: server bokeh

LS, 关于同一主题的所有答案都无法帮助我解决更新问题。我认为这与dfs = df.sort_values(by = ['E'])有关。我使用所有最新版本的库。 bokeh网站上的示例在我的配置上运行良好。通过更新按钮,我希望允许用户选择首选的排序顺序。当该部分工作时,将添加另外两个排序按钮。 这是我的代码:

import pandas as pd
from bokeh.plotting import figure, curdoc
from bokeh.models import ColumnDataSource
from bokeh.layouts import gridplot
from bokeh.models import Button

df = pd.DataFrame(dict(A=["AMS", "LHR", "FRA", "PTY", "CGD"], S=[7,-5,-3,3,2], E=[8,3,-2,5,8], C=[5,2,7,-3,-4]))

source = ColumnDataSource(df)

options = dict(plot_width=300, plot_height=200,
               tools="pan,wheel_zoom,box_zoom,box_select,lasso_select")

button = Button(label="Change Sort to E")

p1 = figure(y_range=source.data['A'].tolist(), title="S", **options)
p1.hbar(y='A', right="S", height=0.2, source=source)


p2 = figure(y_range=source.data['A'].tolist(), title="E", **options)
p2.hbar(y="A", right="E", height=0.2, source=source)


p3 = figure(y_range=source.data['A'].tolist(), title="C", **options)
p3.hbar(y="A", right="C", height=0.2, source=source)


def update():
    dfs = df.sort_values(by=['E'])
    source.data = ColumnDataSource.from_df(dfs)


button.on_click(update)

p = gridplot([[button], [p1, p2, p3]], toolbar_location="right")

curdoc().add_root(p)

我通过以下方式运行服务器:bokeh serve --show app.py --port 5009

非常感谢您完成更新。

1 个答案:

答案 0 :(得分:0)

如果要更改分类轴上的事物顺序,则必须更新范围。轴上的因子顺序完全由您为范围配置的因子顺序指定,因此您将需要重新排序因子以匹配所需的排序顺序。因此,类似:

$connectionName = "AzureRunAsConnection"
try
{
    # Get the connection "AzureRunAsConnection "
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

    "Logging in to Azure..."
    $null = Add-AzureRmAccount `
        -ServicePrincipal `
        -TenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
}
catch {
    if (!$servicePrincipalConnection)
    {
        $ErrorMessage = "Connection $connectionName not found."
        throw $ErrorMessage
    } else{
        Write-Error -Message $_.Exception
        throw $_.Exception
    }
}

$null = Select-AzureRmContext -Subscription 'SubscriptionID'
Restart-AzureRmWebApp -ResourceGroupName 'RGroupName' -Name 'webappname'

请参见

https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html#sorted

查看完整(独立)示例。