【发布时间】: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