一个受react.js启发的组件,用于在google colaboratory中构建一个简单的反应式ui。

ColabComponent的Python项目详细描述


COLAB组件

一个受react.js启发的组件,用于在google colaboratory中构建一个简单的反应式ui。

为什么?

有时需要对数据执行一些手动操作。为什么不在colab中构建一个自定义桌面应用呢?

我在react框架的启发下构建了这个组件,在我看来,react框架为快速原型式开发提供了最好的工具,非常适合于自定义数据探索和数据分析工具。

怎么做?

google.colab包提供了在output中运行python函数的接口。再加上python笔记本可以在html上完全呈现,您可以使用python、html、css和javascript构建ui!

安装

在单元格中运行:

!pip3 install ColabComponent

所有必需的依赖项都安装在google提供的环境中。

如何使用?

包使用面向对象的继承,并基于基本类Component

组件api

property nametypedescriptionoverridable
rendermethodthe basic method, where the ui and effects are defined
component_did_mountmethoda hook that is called, when the component is mounted
component_did_updatemethoda hook that is called, when the component is updated
displaymethodrun to display the component
register_effectmethodregisters a python function such that it can be used within the HTML code
statedictholds the info about the state of the component
set_statemethodthe preferred way of updating the component state

示例

fromColabComponentimportComponentclassCounter(Component):def__init__(self):super().__init__()self.state={'number':1}self.use_add=self.register_effect('add',self.add)defrender(self):returnf'''      <h1>{self.state['number']}</h1>      <button onclick="{self.use_add()}">+1</button>    '''defcomponent_did_mount(self):print('mounted')defcomponent_did_update(self):print('updated')defadd(self):self.set_state({'number':self.state['number']+1})Counter().display()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android HttpClient cookies   如何使用Java在远程系统上运行SSH命令?   java从字符串数组中的字符串末尾删除“,”   在One plus 3t手机上,当应用程序被终止或从最近的应用程序中刷出时,java Android FCM推送通知不起作用   java如何使垂直滚动条始终位于jtable的末尾   在java中解析迄今为止“未知”的字符串   javascript在Java中获取Nashorn JsonObject   java windows 10和ubuntu可以使用相同的JDK吗?   java在不同的文件中记录不同的日志。但所有日志都放在同一个文件中   具有特定jdk的java Gradle构建项目   xml Java web服务生成错误响应   javascript Jaggery文件更改不显示   java输出二进制搜索树数组   将BufferedReader解析为JSON对象时,java在位置处意外标记文件结尾