【问题标题】:Apache Zeppelin python to angular binding does not happen all the time, unbinding gives errorApache Zeppelin python到角度绑定不会一直发生,取消绑定会出错
【发布时间】:2021-08-07 05:59:42
【问题描述】:

我已经创建了一个带有倒数计时器的角度下载按钮,作为更大的 Apache Zeppelin 笔记本的一部分(此示例更改了下面的 URL)。倒计时完成后,该按钮将被禁用。我通过z.angularBind() 绑定python 变量,所以我的角度段落可以使用它们。这似乎与back-end API calls 一致。但是,有时(并且不一致地)绑定不会成功发生,因此按钮不会显示,因为timer 不存在。我已经通过在按钮下方显示绑定值来验证这一点,它们是空的,但只是有时。

这是我的三个连续的 zeppelin notebook 段落:

%python
# z.angularUnbind("url")
bunny = 'https://positively.com/files/bunny-on-side.jpg'
z.angularBind("url", bunny)
%angular
<div>
    <a ng-if="timer>=0" ng-href="{{ url }}" class="btn btn-primary">Download a bunny image</a>
    <a ng-if="timer<0" ng-href="{{ url }}" class="btn btn-primary" disabled>Button Expired</a>
    <br>
    <em>Countdown: {{ timer }}</em>
</div>
<br>
Variables: {{ timer }}, {{ url }}
%python
import time
counter = 10
while counter >= 0:
    z.angularBind("timer", counter)
    time.sleep(1)
    counter -= 1
z.angularBind("timer", counter)

当我重新打开笔记本或导入然后第一次运行时,连续重新运行同一笔记本时可能会出现此问题。下图是 Zeppelin 运行后问题的样子。任何建议都非常感谢,谢谢!

这是正确运行时它应该一直看起来的样子:

接着是:

我试图在第一个 python 段落的开头z.angularUnbind() 我的变量以防变量在某处发生冲突(已注释掉),但得到了以下错误,几乎看起来angularUnbind() 期待前端 API,让我特别困惑。将段落 id 作为第二个参数并不能解决错误消息。

Py4JError: An error occurred while calling o0.angularUnbind. Trace:
py4j.Py4JException: Method angularUnbind([class java.lang.String, class java.lang.String]) does not exist
    at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
    at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
    at py4j.Gateway.invoke(Gateway.java:274)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:238)
    at java.lang.Thread.run(Thread.java:748)

【问题讨论】:

    标签: python-3.x angularjs data-binding binding apache-zeppelin


    【解决方案1】:
    %python
    z.z.angularUnbind("url")
    bunny = 'https://positively.com/files/bunny-on-side.jpg'
    z.z.angularBind("url", bunny)
    

    它应该可以工作,对 python 代码进行上述更改。

    通过 ZeppelinContext,您可以将变量绑定/取消绑定到 AngularJS 视图。目前,它仅适用于 Spark Interpreter (scala)

    【讨论】:

    • 这似乎在初步测试中对我有用,我会在继续测试笔记本时更新。我没有使用 spark,只是普通的 Python,这也可能是限制(但它有时似乎工作?)谢谢!
    猜你喜欢
    • 2018-02-06
    • 2011-03-16
    • 1970-01-01
    • 2018-07-11
    • 2020-10-26
    • 1970-01-01
    • 2021-04-12
    • 2018-09-26
    • 2015-10-13
    相关资源
    最近更新 更多