ex4nicegui 0.6.6__tar.gz → 0.6.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. ex4nicegui-0.6.6/README.md → ex4nicegui-0.6.7/PKG-INFO +1245 -1120
  2. ex4nicegui-0.6.6/PKG-INFO → ex4nicegui-0.6.7/README.md +274 -173
  3. ex4nicegui-0.6.7/ex4nicegui/libs/gsap/.DS_Store +0 -0
  4. ex4nicegui-0.6.7/ex4nicegui/libs/gsap/gsap.mjs +6 -0
  5. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/EChartsComponent/ECharts.js +19 -9
  6. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/aggrid.py +3 -3
  7. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/base.py +10 -0
  8. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/button.py +4 -4
  9. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/checkbox.py +3 -3
  10. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/circular_progress.py +3 -3
  11. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/color_picker.py +4 -4
  12. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/column.py +3 -2
  13. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/date.py +4 -9
  14. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/echarts.py +30 -12
  15. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/expansion.py +3 -2
  16. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/icon.py +4 -4
  17. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/image.py +3 -3
  18. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/input.py +4 -4
  19. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/knob.py +3 -3
  20. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/label.py +4 -3
  21. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/linear_progress.py +4 -4
  22. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/number.py +22 -4
  23. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/radio.py +4 -4
  24. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/select.py +4 -4
  25. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/slider.py +3 -3
  26. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/switch.py +3 -3
  27. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/tab_panels.py +14 -2
  28. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/table.py +5 -4
  29. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/tabs.py +3 -2
  30. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/textarea.py +3 -3
  31. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/q_pagination.py +3 -2
  32. ex4nicegui-0.6.7/pyproject.toml +34 -0
  33. ex4nicegui-0.6.6/ex4nicegui.egg-info/PKG-INFO +0 -1120
  34. ex4nicegui-0.6.6/ex4nicegui.egg-info/SOURCES.txt +0 -157
  35. ex4nicegui-0.6.6/ex4nicegui.egg-info/dependency_links.txt +0 -1
  36. ex4nicegui-0.6.6/ex4nicegui.egg-info/not-zip-safe +0 -1
  37. ex4nicegui-0.6.6/ex4nicegui.egg-info/requires.txt +0 -4
  38. ex4nicegui-0.6.6/ex4nicegui.egg-info/top_level.txt +0 -1
  39. ex4nicegui-0.6.6/setup.cfg +0 -4
  40. ex4nicegui-0.6.6/setup.py +0 -54
  41. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/LICENSE +0 -0
  42. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/__init__.py +0 -0
  43. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/__init__.py +0 -0
  44. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/dataSource.py +0 -0
  45. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/dataSourceFacade.py +0 -0
  46. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/__init__.py +0 -0
  47. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/containers.py +0 -0
  48. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/layouts.py +0 -0
  49. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/models.py +0 -0
  50. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/text.py +0 -0
  51. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/ui_aggrid.py +0 -0
  52. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/ui_date_picker.js +0 -0
  53. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/ui_date_picker.py +0 -0
  54. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/ui_echarts.py +0 -0
  55. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/ui_radio.py +0 -0
  56. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/ui_range.py +0 -0
  57. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/ui_select.py +0 -0
  58. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/ui_slider.py +0 -0
  59. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/elements/ui_table.py +0 -0
  60. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/index.py +0 -0
  61. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/protocols.py +0 -0
  62. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/bi/types.py +0 -0
  63. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/experimental_/__init__.py +0 -0
  64. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/experimental_/gridLayout/__init__.py +0 -0
  65. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/experimental_/gridLayout/index.py +0 -0
  66. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/gsap/__init__.py +0 -0
  67. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/gsap/gsap.py +0 -0
  68. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/gsap/timeline.js +0 -0
  69. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/gsap/timeline.py +0 -0
  70. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/gsap/wrapGsap.js +0 -0
  71. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/layout/__init__.py +0 -0
  72. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/layout/gridFlex/GridFlex.js +0 -0
  73. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/layout/gridFlex/__init__.py +0 -0
  74. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/layout/gridFlex/gridFlex.py +0 -0
  75. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/layout/gridFlex/utils.py +0 -0
  76. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/layout/rxFlex/__init__.py +0 -0
  77. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/layout/rxFlex/index.py +0 -0
  78. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/layout/rxFlex/types.py +0 -0
  79. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/__init__.py +0 -0
  80. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/d3/__init__.py +0 -0
  81. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/d3/d3-color.ems.js +0 -0
  82. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/d3/d3-dispatch.ems.js +0 -0
  83. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/d3/d3-drag.ems.js +0 -0
  84. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/d3/d3-ease.ems.js +0 -0
  85. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/d3/d3-interpolate.ems.js +0 -0
  86. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/d3/d3-selection.ems.js +0 -0
  87. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/d3/d3-timer.ems.js +0 -0
  88. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/d3/d3-transition.ems.js +0 -0
  89. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/d3/d3-zoom.ems.js +0 -0
  90. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/CSSPlugin.js +0 -0
  91. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/CSSRulePlugin.js +0 -0
  92. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/CustomEase.js +0 -0
  93. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/Draggable.js +0 -0
  94. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/EasePack.js +0 -0
  95. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/EaselPlugin.js +0 -0
  96. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/Flip.js +0 -0
  97. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/MotionPathPlugin.js +0 -0
  98. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/Observer.js +0 -0
  99. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/PixiPlugin.js +0 -0
  100. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/ScrollToPlugin.js +0 -0
  101. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/ScrollTrigger.js +0 -0
  102. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/TextPlugin.js +0 -0
  103. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/__init__.py +0 -0
  104. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/all.js +0 -0
  105. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/gsap-core.js +0 -0
  106. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/utils/__init__.py +0 -0
  107. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/utils/matrix.js +0 -0
  108. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/utils/paths.js +0 -0
  109. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/libs/gsap/utils/strings.js +0 -0
  110. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/EChartsComponent/ECharts.py +0 -0
  111. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/EChartsComponent/__init__.py +0 -0
  112. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/EChartsComponent/events.py +0 -0
  113. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/EChartsComponent/types.py +0 -0
  114. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/EChartsComponent/utils.py +0 -0
  115. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/UseDraggable/UseDraggable.js +0 -0
  116. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/UseDraggable/UseDraggable.py +0 -0
  117. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/UseDraggable/__init__.py +0 -0
  118. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/__init__.py +0 -0
  119. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/deferredTask.py +0 -0
  120. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/dropZone/__init__.py +0 -0
  121. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/dropZone/dropZone.js +0 -0
  122. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/dropZone/dropZone.py +0 -0
  123. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/empty.js +0 -0
  124. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/empty.py +0 -0
  125. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/fileWatcher.py +0 -0
  126. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/local_file_picker.py +0 -0
  127. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/mermaid/__init__.py +0 -0
  128. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/mermaid/mermaid.js +0 -0
  129. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/mermaid/mermaid.py +0 -0
  130. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/__init__.py +0 -0
  131. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/card.py +0 -0
  132. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/drawer.py +0 -0
  133. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/element.py +0 -0
  134. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/grid.py +0 -0
  135. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/html.js +0 -0
  136. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/html.py +0 -0
  137. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/row.py +0 -0
  138. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/tab.py +0 -0
  139. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/tab_panel.py +0 -0
  140. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/upload.py +0 -0
  141. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/officials/utils.py +0 -0
  142. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/rxui.py +0 -0
  143. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/transitionGroup.js +0 -0
  144. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/transitionGroup.py +0 -0
  145. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/useMouse/UseMouse.js +0 -0
  146. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/useMouse/UseMouse.py +0 -0
  147. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/useMouse/__init__.py +0 -0
  148. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/usePagination.py +0 -0
  149. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/utils.py +0 -0
  150. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/vfor.js +0 -0
  151. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/vfor.py +0 -0
  152. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/reactive/vmodel.py +0 -0
  153. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/tools/__init__.py +0 -0
  154. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/tools/debug.py +0 -0
  155. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/utils/__init__.py +0 -0
  156. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/utils/apiEffect.py +0 -0
  157. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/utils/asyncComputed.py +0 -0
  158. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/utils/clientScope.py +0 -0
  159. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/utils/common.py +0 -0
  160. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/utils/effect.py +0 -0
  161. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/utils/scheduler.py +0 -0
  162. {ex4nicegui-0.6.6 → ex4nicegui-0.6.7}/ex4nicegui/utils/signals.py +0 -0
@@ -1,1120 +1,1245 @@
1
- # ex4nicegui
2
- [ENGLISH README](./README.en.md)
3
-
4
-
5
- - [教程](#教程)
6
- - [安装](#-安装)
7
- - [使用](#-使用)
8
- - [功能](#-功能)
9
- - [BI 模块](#bi-模块)
10
-
11
- [nicegui](https://github.com/zauberzeug/nicegui) 做的扩展库。内置响应式组件,完全实现数据响应式界面编程。
12
-
13
-
14
- ## 教程
15
- [头条文章-秒杀官方实现,python界面库,去掉90%事件代码的nicegui](https://www.toutiao.com/item/7253786340574265860/)
16
-
17
- [微信公众号-秒杀官方实现,python界面库,去掉90%事件代码的nicegui](https://mp.weixin.qq.com/s?__biz=MzUzNDk1MTc5Mw==&mid=2247486796&idx=1&sn=457ed6fb9d6a25145f7704d5197d670d&chksm=fa8daf52cdfa2644bede50ae7f2551162ecaedecafec231ee4ce8f28775a599f8669ecf06af1#rd)
18
-
19
-
20
- ## 📦 安装
21
-
22
- ```
23
- pip install ex4nicegui -U
24
- ```
25
-
26
-
27
- ## 示例项目
28
- - [入门](./examples/basic/)
29
- - [todo list mvc](./examples/todomvc/)
30
-
31
- ---
32
-
33
- ## 🦄 使用
34
-
35
- ```python
36
- from nicegui import ui
37
- from ex4nicegui import ref_computed, effect, to_ref
38
- from ex4nicegui.reactive import rxui
39
-
40
- # 定义响应式数据
41
- r_input = to_ref("")
42
-
43
- # 按照 nicegui 使用方式传入响应式数据即可
44
- rxui.input(value=r_input)
45
- rxui.label(r_input)
46
-
47
- ui.run()
48
- ```
49
- ![](./asset/sync_input.gif)
50
-
51
-
52
- ### 提供 echarts 图表组件
53
-
54
- ```python
55
- from nicegui import ui
56
- from ex4nicegui import ref_computed, effect, to_ref
57
- from ex4nicegui.reactive import rxui
58
-
59
- r_input = to_ref("")
60
-
61
- # ref_computed 创建只读响应式变量
62
- # 函数中使用任意其他响应式变量,会自动关联
63
- @ref_computed
64
- def cp_echarts_opts():
65
- return {
66
- "title": {"text": r_input.value}, #字典中使用任意响应式变量,通过 .value 获取值
67
- "xAxis": {
68
- "type": "category",
69
- "data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
70
- },
71
- "yAxis": {"type": "value"},
72
- "series": [
73
- {
74
- "data": [120, 200, 150, 80, 70, 110, 130],
75
- "type": "bar",
76
- "showBackground": True,
77
- "backgroundStyle": {"color": "rgba(180, 180, 180, 0.2)"},
78
- }
79
- ],
80
- }
81
-
82
- input = rxui.input("输入内容,图表标题会同步", value=r_input)
83
- # 通过响应式组件对象的 element 属性,获取原生 nicegui 组件对象
84
- input.element.classes("w-full")
85
-
86
- rxui.echarts(cp_echarts_opts)
87
-
88
- ui.run()
89
- ```
90
- ![](./asset/asyc_echarts_title.gif)
91
-
92
-
93
- ### echarts 图表鼠标事件
94
-
95
- `on` 函数参数 `event_name` 以及 `query` 使用,查看[echarts 事件中文文档](https://echarts.apache.org/handbook/zh/concepts/event/)
96
-
97
-
98
- 以下例子绑定鼠标单击事件
99
- ```python
100
- from nicegui import ui
101
- from ex4nicegui.reactive import rxui
102
-
103
- opts = {
104
- "xAxis": {"type": "value", "boundaryGap": [0, 0.01]},
105
- "yAxis": {
106
- "type": "category",
107
- "data": ["Brazil", "Indonesia", "USA", "India", "China", "World"],
108
- },
109
- "series": [
110
- {
111
- "name": "first",
112
- "type": "bar",
113
- "data": [18203, 23489, 29034, 104970, 131744, 630230],
114
- },
115
- {
116
- "name": "second",
117
- "type": "bar",
118
- "data": [19325, 23438, 31000, 121594, 134141, 681807],
119
- },
120
- ],
121
- }
122
-
123
- bar = rxui.echarts(opts)
124
-
125
- def on_click(e: rxui.echarts.EChartsMouseEventArguments):
126
- ui.notify(f"on_click:{e.seriesName}:{e.name}:{e.value}")
127
-
128
-
129
- bar.on("click", on_click)
130
- ```
131
-
132
-
133
- 以下例子只针对指定系列触发鼠标划过事件
134
- ```python
135
- from nicegui import ui
136
- from ex4nicegui.reactive import rxui
137
-
138
- opts = {
139
- "xAxis": {"type": "value", "boundaryGap": [0, 0.01]},
140
- "yAxis": {
141
- "type": "category",
142
- "data": ["Brazil", "Indonesia", "USA", "India", "China", "World"],
143
- },
144
- "series": [
145
- {
146
- "name": "first",
147
- "type": "bar",
148
- "data": [18203, 23489, 29034, 104970, 131744, 630230],
149
- },
150
- {
151
- "name": "second",
152
- "type": "bar",
153
- "data": [19325, 23438, 31000, 121594, 134141, 681807],
154
- },
155
- ],
156
- }
157
-
158
- bar = rxui.echarts(opts)
159
-
160
- def on_first_series_mouseover(e: rxui.echarts.EChartsMouseEventArguments):
161
- ui.notify(f"on_first_series_mouseover:{e.seriesName}:{e.name}:{e.value}")
162
-
163
-
164
- bar.on("mouseover", on_first_series_mouseover, query={"seriesName": "first"})
165
-
166
- ui.run()
167
- ```
168
- ---
169
-
170
-
171
- ## 响应式
172
-
173
- ```python
174
- from ex4nicegui import (
175
- to_ref,
176
- ref_computed,
177
- on,
178
- effect,
179
- effect_refreshable,
180
- batch,
181
- event_batch,
182
- deep_ref,
183
- async_computed
184
- )
185
- ```
186
- 常用 `to_ref`,`deep_ref`,`effect`,`ref_computed`,`on`,`async_computed`
187
-
188
- ---
189
-
190
- ### `to_ref`
191
- 定义响应式对象,通过 `.value` 读写
192
- ```python
193
- a = to_ref(1)
194
- b = to_ref("text")
195
-
196
- a.value =2
197
- b.value = 'new text'
198
-
199
- print(a.value)
200
- ```
201
-
202
- 当值为复杂对象时,默认不会保持嵌套对象的响应性。
203
- ```python
204
- a = to_ref([1,2])
205
-
206
- @effect
207
- def _():
208
- print('len:',len(a.value))
209
-
210
- # 不会触发 effect
211
- a.value.append(10)
212
-
213
- # 整个替换则会触发
214
- a.value = [1,2,10]
215
- ```
216
-
217
- 参数 `is_deep` 设置为 `True` 时,能得到深度响应能力
218
-
219
- ```python
220
- a = to_ref([1,2],is_deep=True)
221
-
222
- @effect
223
- def _():
224
- print('len:',len(a.value))
225
-
226
- # print 3
227
- a.value.append(10)
228
-
229
- ```
230
-
231
- > `deep_ref` 等价于 `is_deep` 设置为 `True` 时的 `to_ref`
232
-
233
- ---
234
-
235
- ### `deep_ref`
236
- 等价于 `is_deep` 设置为 `True` 时的 `to_ref`。
237
-
238
- 当数据源为列表、字典或自定义类时,特别有用。通过 `.value` 获取的对象为代理对象
239
- ```python
240
- data = [1,2,3]
241
- data_ref = deep_ref(data)
242
-
243
- assert data_ref.value is not data
244
- ```
245
-
246
- 通过 `to_raw` 可以获取原始对象
247
- ```python
248
- from ex4nicegui import to_raw, deep_ref
249
-
250
- data = [1, 2, 3]
251
- data_ref = deep_ref(data)
252
-
253
- assert data_ref.value is not data
254
- assert to_raw(data_ref.value) is data
255
- ```
256
-
257
-
258
- ---
259
-
260
- ### `effect`
261
- 接受一个函数,自动监控函数中使用到的响应式对象变化,从而自动执行函数
262
-
263
- ```python
264
- a = to_ref(1)
265
- b = to_ref("text")
266
-
267
-
268
- @effect
269
- def auto_run_when_ref_value():
270
- print(f"a:{a.value}")
271
-
272
-
273
- def change_value():
274
- a.value = 2
275
- b.value = "new text"
276
-
277
-
278
- ui.button("change", on_click=change_value)
279
- ```
280
-
281
- 首次执行 effect ,函数`auto_run_when_ref_value`将被执行一次.之后点击按钮,改变 `a` 的值(通过 `a.value`),函数`auto_run_when_ref_value`再次执行
282
-
283
- > 切忌把大量数据处理逻辑分散在多个 `on` 或 `effect` 中,`on` 或 `effect` 中应该大部分为界面操作逻辑,而非响应式数据处理逻辑
284
-
285
- ---
286
-
287
- ### `ref_computed`
288
- `effect` 具备一样的功能,`ref_computed` 还能从函数中返回结果。一般用于从 `to_ref` 中进行二次计算
289
-
290
- ```python
291
- a = to_ref(1)
292
- a_square = ref_computed(lambda: a.value * 2)
293
-
294
-
295
- @effect
296
- def effect1():
297
- print(f"a_square:{a_square.value}")
298
-
299
-
300
- def change_value():
301
- a.value = 2
302
-
303
-
304
- ui.button("change", on_click=change_value)
305
- ```
306
-
307
- 点击按钮后,`a.value` 值被修改,从而触发 `a_square` 重新计算.由于 `effect1` 中读取了 `a_square` 的值,从而触发 `effect1` 执行
308
-
309
- > `ref_computed` 是只读的 `to_ref`
310
-
311
-
312
- 如果你更喜欢通过类组织代码,`ref_computed` 同样支持作用到实例方法上
313
-
314
- ```python
315
- class MyState:
316
- def __init__(self) -> None:
317
- self.r_text = to_ref("")
318
-
319
- @ref_computed
320
- def post_text(self):
321
- return self.r_text.value + "post"
322
-
323
- state = MyState()
324
-
325
- rxui.input(value=state.r_text)
326
- rxui.label(state.post_text)
327
- ```
328
-
329
- ---
330
-
331
- ### `async_computed`
332
- 二次计算中需要使用异步函数时,使用 `async_computed`
333
- ```python
334
-
335
- # 模拟长时间执行的异步函数
336
- async def long_time_query(input: str):
337
- await asyncio.sleep(2)
338
- num = random.randint(20, 100)
339
- return f"query result[{input=}]:{num=}"
340
-
341
-
342
- search = to_ref("")
343
- evaluating = to_ref(False)
344
-
345
- @async_computed(search, evaluating=evaluating, init="")
346
- async def search_result():
347
- return await long_time_query(search.value)
348
-
349
- rxui.lazy_input(value=search)
350
-
351
- rxui.label(
352
- lambda: "查询中" if evaluating.value else "上方输入框输入内容并回车搜索"
353
- )
354
- rxui.label(search_result)
355
-
356
- ```
357
-
358
- - `async_computed` 第一个参数必须明确指定需要监控的响应式数据. 使用列表可以同时指定多个响应式数据
359
- - 参数 `evaluating` 为 bool 类型的响应式数据,当异步函数执行中,此变量值为 `True`,计算结束后为 `False`
360
- - 参数 `init` 指定初始结果
361
-
362
-
363
- ---
364
-
365
- ### `on`
366
- 类似 `effect` 的功能,但是 `on` 需要明确指定监控的响应式对象
367
-
368
- ```python
369
-
370
- a1 = to_ref(1)
371
- a2 = to_ref(10)
372
- b = to_ref("text")
373
-
374
-
375
- @on(a1)
376
- def watch_a1_only():
377
- print(f"watch_a1_only ... a1:{a1.value},a2:{a2.value}")
378
-
379
-
380
- @on([a1, b], onchanges=True)
381
- def watch_a1_and_b():
382
- print(f"watch_a1_and_b ... a1:{a1.value},a2:{a2.value},b:{b.value}")
383
-
384
-
385
- def change_a1():
386
- a1.value += 1
387
- ui.notify("change_a1")
388
-
389
-
390
- ui.button("change a1", on_click=change_a1)
391
-
392
-
393
- def change_a2():
394
- a2.value += 1
395
- ui.notify("change_a2")
396
-
397
-
398
- ui.button("change a2", on_click=change_a2)
399
-
400
-
401
- def change_b():
402
- b.value += "x"
403
- ui.notify("change_b")
404
-
405
-
406
- ui.button("change b", on_click=change_b)
407
-
408
- ```
409
-
410
- - 参数 `onchanges` 为 True 时(默认值为 False),指定的函数不会在绑定时执行
411
-
412
-
413
- > 切忌把大量数据处理逻辑分散在多个 `on` 或 `effect` 中,`on` 或 `effect` 中应该大部分为界面操作逻辑,而非响应式数据处理逻辑
414
-
415
- ---
416
-
417
- ### `new_scope`
418
-
419
- 默认情况下,所有检测函数在客户端连接断开时自动销毁。如果需要更细粒度的控制,可以使用 `new_scope`
420
-
421
- ```python
422
- from nicegui import ui
423
- from ex4nicegui import rxui, to_ref, effect, new_scope
424
-
425
- a = to_ref(0.0)
426
-
427
- scope1 = new_scope()
428
-
429
- @scope1.run
430
- def _():
431
- @effect
432
- def _():
433
- print(f"scope 1:{a.value}")
434
-
435
-
436
- rxui.number(value=a)
437
- rxui.button("dispose scope 1", on_click=scope1.dispose)
438
- ```
439
-
440
- ---
441
-
442
-
443
- ## 组件功能
444
-
445
- ### vmodel
446
- 在表单输入元素或组件上创建双向绑定。
447
-
448
- 简单值类型的 `ref` 默认支持双向绑定
449
- ```python
450
- from ex4nicegui import rxui, to_ref, deep_ref
451
-
452
- data = to_ref("init")
453
-
454
- rxui.label(lambda: f"{data.value=}")
455
- # 默认就是双向绑定
456
- rxui.input(value=data)
457
- ```
458
-
459
- - 简单值类型一般是 `str`,`int` 等不可变值类型
460
-
461
- 当使用复杂数据结构时,会使用 `deep_ref` 保持嵌套值的响应性
462
- ```python
463
- data = deep_ref({"a": 1, "b": [1, 2, 3, 4]})
464
-
465
- rxui.label(lambda: f"{data.value=!s}")
466
-
467
- # 当前版本没有任何绑定效果.或许未来的版本可以解决
468
- rxui.input(value=data.value["a"])
469
-
470
- # 只读绑定.其他途径修改了 `data.value["a"]` ,此输入框会同步,但反过来不行
471
- rxui.input(value=lambda: data.value["a"])
472
-
473
- # 要使用 vmodel 才能双向绑定
474
- rxui.input(value=rxui.vmodel(data.value["a"]))
475
- ```
476
-
477
- - 第一个输入框将完全失去响应性,因为代码等价于直接传入一个数值`1`
478
- - 第二个输入框由于使用函数,将得到读取响应性(第三个输入框输入值,将得到同步)
479
- - 第三个输入框,使用 `rxui.vmodel` 包裹,即可实现双向绑定
480
-
481
- 多数在配合 `vfor` 时使用 `vmodel`,可参考 [todo list 案例](./examples/todomvc/)
482
-
483
-
484
- ### vfor
485
- 基于列表响应式数据,渲染列表组件。每项组件按需更新。数据项支持字典或任意类型对象
486
-
487
- ```python
488
- from nicegui import ui
489
- from ex4nicegui.reactive import rxui
490
- from ex4nicegui import deep_ref, ref_computed
491
- from typing import Dict
492
-
493
- # refs
494
- items = deep_ref(
495
- [
496
- {"id": 1, "message": "foo", "done": False},
497
- {"id": 2, "message": "bar", "done": True},
498
- ]
499
- )
500
-
501
- # ref_computeds
502
- @ref_computed
503
- def done_count_info():
504
- return f"done count:{sum(item['done'] for item in items.value)}"
505
-
506
- # method
507
- def check():
508
- for item in items.value:
509
- item["done"] = not item["done"]
510
-
511
-
512
- # ui
513
- rxui.label(done_count_info)
514
- ui.button("check", on_click=check)
515
-
516
-
517
- @rxui.vfor(items,key='id')
518
- def _(store: rxui.VforStore[Dict]):
519
- # 函数中构建每一行数据的界面
520
- item = store.get() # 通过 store.get 获取对应行的响应式对象(相当于每行的数据 to_ref(...))
521
- mes = rxui.vmodel(item.value['message']) # 复杂结构默认没有双向绑定,需要使用 `vmodel`
522
-
523
- # 输入框输入内容,可以看到单选框的标题同步变化
524
- with ui.card():
525
- with ui.row():
526
- rxui.input(value=mes)
527
- rxui.label(lambda: f"{mes.value=!s}")
528
- rxui.checkbox(text=mes, value=rxui.vmodel(item.value['done']))
529
-
530
- ```
531
-
532
- - `rxui.vfor` 装饰器到自定义函数
533
- - 第一个参数传入响应式列表。列表中每一项可以是字典或其他对象(`dataclasses` 等等)
534
- - 第二个参数 `key`: 为了可以跟踪每个节点的标识,从而重用和重新排序现有的元素,你可以为每个元素对应的块提供一个唯一的 key 。默认情况使用列表元素索引。
535
- - 自定义函数带有一个参数。通过 `store.get` 可以获取当前行的响应式对象
536
-
537
- > vfor 渲染的项目,只有在新增数据时,才会创建
538
-
539
-
540
- ---
541
-
542
- ### 绑定类名
543
-
544
- 所有的组件类提供 `bind_classes` 用于绑定 `class`,支持三种不同的数据结构。
545
-
546
- 绑定字典
547
-
548
- ```python
549
- bg_color = to_ref(False)
550
- has_error = to_ref(False)
551
-
552
- rxui.label("test").bind_classes({"bg-blue": bg_color, "text-red": has_error})
553
-
554
- rxui.switch("bg_color", value=bg_color)
555
- rxui.switch("has_error", value=has_error)
556
- ```
557
-
558
- 字典键值为类名,对应值为 bool 的响应式变量。当响应式值为 `True`,类名应用到组件 class
559
-
560
-
561
- ---
562
-
563
- 绑定返回值为字典的响应式变量
564
-
565
- ```python
566
- bg_color = to_ref(False)
567
- has_error = to_ref(False)
568
-
569
- class_obj = ref_computed(
570
- lambda: {"bg-blue": bg_color.value, "text-red": has_error.value}
571
- )
572
-
573
- rxui.switch("bg_color", value=bg_color)
574
- rxui.switch("has_error", value=has_error)
575
- rxui.label("bind to ref_computed").bind_classes(class_obj)
576
- # or direct function passing
577
- rxui.label("bind to ref_computed").bind_classes(
578
- lambda: {"bg-blue": bg_color.value, "text-red": has_error.value}
579
- )
580
- ```
581
-
582
- ---
583
-
584
- 绑定为列表
585
-
586
- ```python
587
- bg_color = to_ref("red")
588
- bg_color_class = ref_computed(lambda: f"bg-{bg_color.value}")
589
-
590
- text_color = to_ref("green")
591
- text_color_class = ref_computed(lambda: f"text-{text_color.value}")
592
-
593
- rxui.select(["red", "green", "yellow"], label="bg color", value=bg_color)
594
- rxui.select(["red", "green", "yellow"], label="text color", value=text_color)
595
-
596
- rxui.label("binding to arrays").bind_classes([bg_color_class, text_color_class])
597
-
598
- ```
599
-
600
- 列表中每个元素为返回类名的响应式变量
601
-
602
- ---
603
-
604
- ### bind-style
605
-
606
- ```python
607
- from nicegui import ui
608
- from ex4nicegui.reactive import rxui
609
- from ex4nicegui.utils.signals import to_ref
610
-
611
-
612
- bg_color = to_ref("blue")
613
- text_color = to_ref("red")
614
-
615
- rxui.label("test").bind_style(
616
- {
617
- "background-color": bg_color,
618
- "color": text_color,
619
- }
620
- )
621
-
622
- rxui.select(["blue", "green", "yellow"], label="bg color", value=bg_color)
623
- rxui.select(["red", "green", "yellow"], label="text color", value=text_color)
624
- ```
625
-
626
- `bind_style` 传入字典,`key` 为样式名字,`value` 为样式值,响应式字符串
627
-
628
-
629
- ---
630
-
631
- ### rxui.echarts
632
- 使用 echarts 制作图表
633
-
634
- ---
635
-
636
- #### rxui.echarts.from_javascript
637
- 从 javascript 代码创建 echart
638
-
639
- ```python
640
- from pathlib import Path
641
-
642
- rxui.echarts.from_javascript(Path("code.js"))
643
- # or
644
- rxui.echarts.from_javascript(
645
- """
646
- (myChart) => {
647
-
648
- option = {
649
- xAxis: {
650
- type: 'category',
651
- data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
652
- },
653
- yAxis: {
654
- type: 'value'
655
- },
656
- series: [
657
- {
658
- data: [120, 200, 150, 80, 70, 110, 130],
659
- type: 'bar'
660
- }
661
- ]
662
- };
663
-
664
- myChart.setOption(option);
665
- }
666
- """
667
- )
668
- ```
669
-
670
- - 函数第一个参数为 echart 实例对象.你需要在函数中通过 `setOption` 完成图表配置
671
-
672
- ---
673
-
674
- #### rxui.echarts.register_map
675
- 注册地图.
676
-
677
- ```python
678
- rxui.echarts.register_map(
679
- "china", "https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json"
680
- )
681
-
682
- rxui.echarts(
683
- {
684
- "geo": {
685
- "map": "china",
686
- "roam": True,
687
- },
688
- "tooltip": {},
689
- "legend": {},
690
- "series": [],
691
- }
692
- )
693
- ```
694
-
695
- - 参数 `map_name` 为自定义的地图名字。注意在图表配置中 `map` 必需对应注册的名字
696
- - 参数 `src` 为有效的地图数据网络链接。
697
-
698
- 你也可以直接提供本地地图数据的json文件路径对象(Path)
699
- ```python
700
- from pathlib import Path
701
-
702
- rxui.echarts.register_map(
703
- "china", Path("map-data.json")
704
- )
705
- ```
706
-
707
- ---
708
-
709
- ### gsap
710
- js 动画库. [gsap文档](https://gsap.com/docs/v3/)
711
-
712
- ```python
713
- from nicegui import ui
714
- from ex4nicegui import gsap
715
- ```
716
-
717
- #### gsap.from_
718
-
719
- 设置起始属性,动画将从设置的属性过渡到原始位置
720
-
721
- ```python
722
-
723
- ui.label("test from").classes("target")
724
- gsap.from_(".target", {"x": 50,'duration':1})
725
-
726
- ```
727
-
728
- 画面加载后,文本起始位置在往右偏移 50px 处,在 1秒 内移动到原始位置上
729
-
730
- - 参数 `targets` 为 css 选择器
731
- - 参数 `vars` 为属性值,具体参考 gsap 文档
732
-
733
- ---
734
-
735
- #### gsap.to
736
-
737
- 设置结束属性,动画将从原始属性过渡到设置的属性
738
-
739
- ```python
740
-
741
- ui.label("test to").classes("target")
742
- gsap.to(".target", {"x": 50,'duration':1})
743
-
744
- ```
745
-
746
- 画面加载后,文本在 1秒 内,从原始位置往后移动 50px
747
-
748
- - 参数 `targets` 为 css 选择器
749
- - 参数 `vars` 为属性值,具体参考 gsap 文档
750
-
751
- ---
752
- #### gsap.run_script
753
-
754
- 通过编写 js 设置动画
755
-
756
- ```python
757
-
758
- gsap.run_script(
759
- r"""function setGsap(gsap) {
760
- gsap.to('.target',{"duration": 0.3,y:60})
761
- }
762
- """)
763
- ```
764
-
765
- - 参数 `script` 可以为文本或 js 后缀的文件 `Path`
766
- - 定义的 js 函数名字并不影响运行,第一个参数为 gsap 对象
767
-
768
- ---
769
-
770
- ## BI 模块
771
-
772
- 以最精简的 apis 创建可交互的数据可视化报表
773
-
774
- ![](./asset/bi_examples1.gif)
775
-
776
- ```python
777
- from nicegui import ui
778
- import pandas as pd
779
- import numpy as np
780
- from ex4nicegui import bi
781
- from ex4nicegui.reactive import rxui
782
- from ex4nicegui import effect, effect_refreshable
783
- from pyecharts.charts import Bar
784
-
785
-
786
- # data ready
787
- def gen_data():
788
- np.random.seed(265)
789
- field1 = ["a1", "a2", "a3", "a4"]
790
- field2 = [f"name{i}" for i in range(1, 11)]
791
- df = (
792
- pd.MultiIndex.from_product([field1, field2], names=["cat", "name"])
793
- .to_frame()
794
- .reset_index(drop=True)
795
- )
796
- df[["idc1", "idc2"]] = np.random.randint(50, 1000, size=(len(df), 2))
797
- return df
798
-
799
-
800
- df = gen_data()
801
-
802
- # 创建数据源
803
- ds = bi.data_source(df)
804
-
805
- # ui
806
- ui.query(".nicegui-content").classes("items-stretch no-wrap")
807
-
808
- with ui.row().classes("justify-evenly"):
809
- # 基于数据源 `ds` 创建界面组件
810
- ds.ui_select("cat").classes("min-w-[10rem]")
811
- ds.ui_select("name").classes("min-w-[10rem]")
812
-
813
-
814
- with ui.grid(columns=2):
815
- # 使用字典配置图表
816
- @ds.ui_echarts
817
- def bar1(data: pd.DataFrame):
818
- data = data.groupby("name").agg({"idc1": "sum", "idc2": "sum"}).reset_index()
819
-
820
- return {
821
- "xAxis": {"type": "value"},
822
- "yAxis": {
823
- "type": "category",
824
- "data": data["name"].tolist(),
825
- "inverse": True,
826
- },
827
- "legend": {"textStyle": {"color": "gray"}},
828
- "series": [
829
- {"type": "bar", "name": "idc1", "data": data["idc1"].tolist()},
830
- {"type": "bar", "name": "idc2", "data": data["idc2"].tolist()},
831
- ],
832
- }
833
-
834
- bar1.classes("h-[20rem]")
835
-
836
- # 使用pyecharts配置图表
837
- @ds.ui_echarts
838
- def bar2(data: pd.DataFrame):
839
- data = data.groupby("name").agg({"idc1": "sum", "idc2": "sum"}).reset_index()
840
-
841
- return (
842
- Bar()
843
- .add_xaxis(data["name"].tolist())
844
- .add_yaxis("idc1", data["idc1"].tolist())
845
- .add_yaxis("idc2", data["idc2"].tolist())
846
- )
847
-
848
- bar2.classes("h-[20rem]")
849
-
850
- # 绑定点击事件,即可实现跳转
851
- @bar2.on_chart_click
852
- def _(e: rxui.echarts.EChartsMouseEventArguments):
853
- ui.open(f"/details/{e.name}", new_tab=True)
854
-
855
-
856
- # 利用响应式机制,你可以随意组合原生 nicegui 组件
857
- label_a1_total = ui.label("")
858
-
859
-
860
- # 当 ds 有变化,都会触发此函数
861
- @effect
862
- def _():
863
- # filtered_data 为过滤后的 DataFrame
864
- df = ds.filtered_data
865
- total = df[df["cat"] == "a1"]["idc1"].sum()
866
- label_a1_total.text = f"idc1 total(cat==a1):{total}"
867
-
868
-
869
- # 你也可以使用 `effect_refreshable`,但需要注意函数中的组件每次都被重建
870
- @effect_refreshable
871
- def _():
872
- df = ds.filtered_data
873
- total = df[df["cat"] == "a2"]["idc1"].sum()
874
- ui.label(f"idc1 total(cat==a2):{total}")
875
-
876
-
877
- # 当点击图表系列时,跳转的页面
878
- @ui.page("/details/{name}")
879
- def details_page(name: str):
880
- ui.label("This table data will not change")
881
- ui.aggrid.from_pandas(ds.data.query(f'name=="{name}"'))
882
-
883
- ui.label("This table will change when the homepage data changes. ")
884
-
885
- @bi.data_source
886
- def new_ds():
887
- return ds.filtered_data[["name", "idc1", "idc2"]]
888
-
889
- new_ds.ui_aggrid()
890
-
891
-
892
- ui.run()
893
- ```
894
-
895
-
896
-
897
- ### 细节
898
-
899
-
900
-
901
-
902
- #### `bi.data_source`
903
- 数据源是 BI 模块的核心概念,所有数据的联动基于此展开。当前版本(0.4.3)中,有两种创建数据源的方式
904
-
905
- 接收 `pandas` `DataFrame`:
906
- ```python
907
- from nicegui import ui
908
- from ex4nicegui import bi
909
- import pandas as pd
910
-
911
- df = pd.DataFrame(
912
- {
913
- "name": list("aabcdf"),
914
- "cls": ["c1", "c2", "c1", "c1", "c3", None],
915
- "value": range(6),
916
- }
917
- )
918
-
919
- ds = bi.data_source(df)
920
- ```
921
-
922
- ---
923
- 有时候,我们希望基于另一个数据源创建新的数据源,此时可以使用装饰器创建联动数据源:
924
- ```python
925
- df = pd.DataFrame(
926
- {
927
- "name": list("aabcdf"),
928
- "cls": ["c1", "c2", "c1", "c1", "c3", None],
929
- "value": range(6),
930
- }
931
- )
932
-
933
- ds = bi.data_source(df)
934
-
935
- @bi.data_source
936
- def new_ds():
937
- # df is pd.DataFrame
938
- df = ds.filtered_data
939
- df=df.copy()
940
- df['value'] = df['value'] * 100
941
- return df
942
-
943
- ds.ui_select('name')
944
- new_ds.ui_aggrid()
945
-
946
- ```
947
-
948
- 注意,由于 `new_ds` 中使用了 `ds.filtered_data` ,因此 `ds` 的变动会触发 `new_ds` 的联动变化,从而导致 `new_ds` 创建的表格组件产生变化
949
-
950
- ---
951
- 通过 `ds.remove_filters` 方法,移除所有筛选状态:
952
- ```python
953
- ds = bi.data_source(df)
954
-
955
- def on_remove_filters():
956
- ds.remove_filters()
957
-
958
- ui.button("remove all filters", on_click=on_remove_filters)
959
-
960
- ds.ui_select("name")
961
- ds.ui_aggrid()
962
- ```
963
- ---
964
-
965
- 通过 `ds.reload` 方法,重设数据源:
966
- ```python
967
-
968
- df = pd.DataFrame(
969
- {
970
- "name": list("aabcdf"),
971
- "cls": ["c1", "c2", "c1", "c1", "c3", None],
972
- "value": range(6),
973
- }
974
- )
975
-
976
- new_df = pd.DataFrame(
977
- {
978
- "name": list("xxyyds"),
979
- "cls": ["cla1", "cla2", "cla3", "cla3", "cla3", None],
980
- "value": range(100, 106),
981
- }
982
- )
983
-
984
- ds = bi.data_source(df)
985
-
986
- def on_remove_filters():
987
- ds.reload(new_df)
988
-
989
- ui.button("reload data", on_click=on_remove_filters)
990
-
991
- ds.ui_select("name")
992
- ds.ui_aggrid()
993
- ```
994
-
995
- ---
996
- #### ui_select
997
-
998
- ```python
999
- from nicegui import ui
1000
- from ex4nicegui import bi
1001
- import pandas as pd
1002
-
1003
- df = pd.DataFrame(
1004
- {
1005
- "name": list("aabcdf"),
1006
- "cls": ["c1", "c2", "c1", "c1", "c3", None],
1007
- "value": range(6),
1008
- }
1009
- )
1010
-
1011
- ds = bi.data_source(df)
1012
-
1013
- ds.ui_select("name")
1014
- ```
1015
-
1016
- 第一个参数 column 指定数据源的列名
1017
-
1018
- ---
1019
- 通过参数 `sort_options` 设置选项顺序:
1020
- ```python
1021
- ds.ui_select("name", sort_options={"value": "desc", "name": "asc"})
1022
-
1023
- ```
1024
-
1025
- ---
1026
- 参数 `exclude_null_value` 设置是否排除空值:
1027
- ```python
1028
- df = pd.DataFrame(
1029
- {
1030
- "cls": ["c1", "c2", "c1", "c1", "c3", None],
1031
- }
1032
- )
1033
-
1034
- ds = bi.data_source(df)
1035
- ds.ui_select("cls", exclude_null_value=True)
1036
- ```
1037
-
1038
- ---
1039
-
1040
- 你可以通过关键字参数,设置原生 nicegui select 组件的参数.
1041
-
1042
- 通过 value 属性,设置默认值:
1043
- ```python
1044
- ds.ui_select("cls",value=['c1','c2'])
1045
- ds.ui_select("cls",multiple=False,value='c1')
1046
-
1047
- ```
1048
-
1049
- 多选时(参数 `multiple` 默认为 True),`value` 需要指定为 list
1050
-
1051
- 单选时,`value` 设置为非 list
1052
-
1053
- ---
1054
-
1055
- #### ui_table
1056
-
1057
- 表格
1058
-
1059
- ```python
1060
- from nicegui import ui
1061
- from ex4nicegui import bi
1062
- import pandas as pd
1063
-
1064
- data = pd.DataFrame({"name": ["f", "a", "c", "b"], "age": [1, 2, 3, 1]})
1065
- ds = bi.data_source(data)
1066
-
1067
- ds.ui_table(
1068
- columns=[
1069
- {"label": "new colA", "field": "colA", "sortable": True},
1070
- ]
1071
- )
1072
-
1073
- ```
1074
-
1075
- - columns 与 nicegui `ui.table` 一致。其中 键值 `field` 对应数据源的列名,如果不存在,则该配置不会生效
1076
- - rows 参数不会生效。因为表格的数据源始终由 data source 控制
1077
-
1078
- ---
1079
-
1080
- #### ui_aggrid
1081
-
1082
-
1083
- ```python
1084
- from nicegui import ui
1085
- from ex4nicegui import bi
1086
- import pandas as pd
1087
-
1088
- data = pd.DataFrame(
1089
- {
1090
- "colA": list("abcde"),
1091
- "colB": [f"n{idx}" for idx in range(5)],
1092
- "colC": list(range(5)),
1093
- }
1094
- )
1095
- df = pd.DataFrame(data)
1096
-
1097
- source = bi.data_source(df)
1098
-
1099
- source.ui_aggrid(
1100
- options={
1101
- "columnDefs": [
1102
- {"headerName": "xx", "field": "no exists"},
1103
- {"headerName": "new colA", "field": "colA"},
1104
- {
1105
- "field": "colC",
1106
- "cellClassRules": {
1107
- "bg-red-300": "x < 3",
1108
- "bg-green-300": "x >= 3",
1109
- },
1110
- },
1111
- ],
1112
- "rowData": [{"colX": [1, 2, 3, 4, 5]}],
1113
- }
1114
- )
1115
- ```
1116
-
1117
- - 参数 options 与 nicegui `ui.aggrid` 一致。其中 `columnDefs` 中的键值 `field` 对应数据源的列名,如果不存在,则该配置不会生效
1118
- - `rowData` 键值不会生效。因为表格的数据源始终由 data source 控制
1119
-
1120
-
1
+ Metadata-Version: 2.1
2
+ Name: ex4nicegui
3
+ Version: 0.6.7
4
+ Summary: Extension library based on nicegui, providing data responsive,BI functionality modules
5
+ Home-page: https://github.com/CrystalWindSnake/ex4nicegui
6
+ License: MIT
7
+ Keywords: nicegui,ex4nicegui,webui
8
+ Author: CrystalWindSnake
9
+ Author-email: 568166495@qq.com
10
+ Requires-Python: >=3.8,<4.0
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Requires-Dist: executing (>=2.0.1,<3.0.0)
19
+ Requires-Dist: nicegui (>=1.4.25,<2.0.0)
20
+ Requires-Dist: signe (>=0.4.14,<0.5.0)
21
+ Project-URL: Repository, https://github.com/CrystalWindSnake/ex4nicegui
22
+ Description-Content-Type: text/markdown
23
+
24
+ # ex4nicegui
25
+ [ENGLISH README](./README.en.md)
26
+
27
+
28
+ - [教程](#教程)
29
+ - [安装](#-安装)
30
+ - [使用](#-使用)
31
+ - [功能](#-功能)
32
+ - [BI 模块](#bi-模块)
33
+
34
+ 对 [nicegui](https://github.com/zauberzeug/nicegui) 做的扩展库。内置响应式组件,完全实现数据响应式界面编程。
35
+
36
+
37
+ ## 教程
38
+ [头条文章-秒杀官方实现,python界面库,去掉90%事件代码的nicegui](https://www.toutiao.com/item/7253786340574265860/)
39
+
40
+ [微信公众号-秒杀官方实现,python界面库,去掉90%事件代码的nicegui](https://mp.weixin.qq.com/s?__biz=MzUzNDk1MTc5Mw==&mid=2247486796&idx=1&sn=457ed6fb9d6a25145f7704d5197d670d&chksm=fa8daf52cdfa2644bede50ae7f2551162ecaedecafec231ee4ce8f28775a599f8669ecf06af1#rd)
41
+
42
+
43
+ ## 📦 安装
44
+
45
+ ```
46
+ pip install ex4nicegui -U
47
+ ```
48
+
49
+
50
+ ## 示例项目
51
+ - [入门](./examples/basic/)
52
+ - [todo list mvc](./examples/todomvc/)
53
+
54
+ ---
55
+
56
+ ## 🦄 使用
57
+
58
+ ```python
59
+ from nicegui import ui
60
+ from ex4nicegui import ref_computed, effect, to_ref
61
+ from ex4nicegui.reactive import rxui
62
+
63
+ # 定义响应式数据
64
+ r_input = to_ref("")
65
+
66
+ # 按照 nicegui 使用方式传入响应式数据即可
67
+ rxui.input(value=r_input)
68
+ rxui.label(r_input)
69
+
70
+ ui.run()
71
+ ```
72
+ ![](./asset/sync_input.gif)
73
+
74
+
75
+ ### 提供 echarts 图表组件
76
+
77
+ ```python
78
+ from nicegui import ui
79
+ from ex4nicegui import ref_computed, effect, to_ref
80
+ from ex4nicegui.reactive import rxui
81
+
82
+ r_input = to_ref("")
83
+
84
+ # ref_computed 创建只读响应式变量
85
+ # 函数中使用任意其他响应式变量,会自动关联
86
+ @ref_computed
87
+ def cp_echarts_opts():
88
+ return {
89
+ "title": {"text": r_input.value}, #字典中使用任意响应式变量,通过 .value 获取值
90
+ "xAxis": {
91
+ "type": "category",
92
+ "data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
93
+ },
94
+ "yAxis": {"type": "value"},
95
+ "series": [
96
+ {
97
+ "data": [120, 200, 150, 80, 70, 110, 130],
98
+ "type": "bar",
99
+ "showBackground": True,
100
+ "backgroundStyle": {"color": "rgba(180, 180, 180, 0.2)"},
101
+ }
102
+ ],
103
+ }
104
+
105
+ input = rxui.input("输入内容,图表标题会同步", value=r_input)
106
+ # 通过响应式组件对象的 element 属性,获取原生 nicegui 组件对象
107
+ input.element.classes("w-full")
108
+
109
+ rxui.echarts(cp_echarts_opts)
110
+
111
+ ui.run()
112
+ ```
113
+ ![](./asset/asyc_echarts_title.gif)
114
+
115
+
116
+ ### echarts 图表鼠标事件
117
+
118
+ `on` 函数参数 `event_name` 以及 `query` 使用,查看[echarts 事件中文文档](https://echarts.apache.org/handbook/zh/concepts/event/)
119
+
120
+
121
+ 以下例子绑定鼠标单击事件
122
+ ```python
123
+ from nicegui import ui
124
+ from ex4nicegui.reactive import rxui
125
+
126
+ opts = {
127
+ "xAxis": {"type": "value", "boundaryGap": [0, 0.01]},
128
+ "yAxis": {
129
+ "type": "category",
130
+ "data": ["Brazil", "Indonesia", "USA", "India", "China", "World"],
131
+ },
132
+ "series": [
133
+ {
134
+ "name": "first",
135
+ "type": "bar",
136
+ "data": [18203, 23489, 29034, 104970, 131744, 630230],
137
+ },
138
+ {
139
+ "name": "second",
140
+ "type": "bar",
141
+ "data": [19325, 23438, 31000, 121594, 134141, 681807],
142
+ },
143
+ ],
144
+ }
145
+
146
+ bar = rxui.echarts(opts)
147
+
148
+ def on_click(e: rxui.echarts.EChartsMouseEventArguments):
149
+ ui.notify(f"on_click:{e.seriesName}:{e.name}:{e.value}")
150
+
151
+
152
+ bar.on("click", on_click)
153
+ ```
154
+
155
+
156
+ 以下例子只针对指定系列触发鼠标划过事件
157
+ ```python
158
+ from nicegui import ui
159
+ from ex4nicegui.reactive import rxui
160
+
161
+ opts = {
162
+ "xAxis": {"type": "value", "boundaryGap": [0, 0.01]},
163
+ "yAxis": {
164
+ "type": "category",
165
+ "data": ["Brazil", "Indonesia", "USA", "India", "China", "World"],
166
+ },
167
+ "series": [
168
+ {
169
+ "name": "first",
170
+ "type": "bar",
171
+ "data": [18203, 23489, 29034, 104970, 131744, 630230],
172
+ },
173
+ {
174
+ "name": "second",
175
+ "type": "bar",
176
+ "data": [19325, 23438, 31000, 121594, 134141, 681807],
177
+ },
178
+ ],
179
+ }
180
+
181
+ bar = rxui.echarts(opts)
182
+
183
+ def on_first_series_mouseover(e: rxui.echarts.EChartsMouseEventArguments):
184
+ ui.notify(f"on_first_series_mouseover:{e.seriesName}:{e.name}:{e.value}")
185
+
186
+
187
+ bar.on("mouseover", on_first_series_mouseover, query={"seriesName": "first"})
188
+
189
+ ui.run()
190
+ ```
191
+ ---
192
+
193
+
194
+ ## 响应式
195
+
196
+ ```python
197
+ from ex4nicegui import (
198
+ to_ref,
199
+ ref_computed,
200
+ on,
201
+ effect,
202
+ effect_refreshable,
203
+ batch,
204
+ event_batch,
205
+ deep_ref,
206
+ async_computed
207
+ )
208
+ ```
209
+ 常用 `to_ref`,`deep_ref`,`effect`,`ref_computed`,`on`,`async_computed`
210
+
211
+ ---
212
+
213
+ ### `to_ref`
214
+ 定义响应式对象,通过 `.value` 读写
215
+ ```python
216
+ a = to_ref(1)
217
+ b = to_ref("text")
218
+
219
+ a.value =2
220
+ b.value = 'new text'
221
+
222
+ print(a.value)
223
+ ```
224
+
225
+ 当值为复杂对象时,默认不会保持嵌套对象的响应性。
226
+ ```python
227
+ a = to_ref([1,2])
228
+
229
+ @effect
230
+ def _():
231
+ print('len:',len(a.value))
232
+
233
+ # 不会触发 effect
234
+ a.value.append(10)
235
+
236
+ # 整个替换则会触发
237
+ a.value = [1,2,10]
238
+ ```
239
+
240
+ 参数 `is_deep` 设置为 `True` 时,能得到深度响应能力
241
+
242
+ ```python
243
+ a = to_ref([1,2],is_deep=True)
244
+
245
+ @effect
246
+ def _():
247
+ print('len:',len(a.value))
248
+
249
+ # print 3
250
+ a.value.append(10)
251
+
252
+ ```
253
+
254
+ > `deep_ref` 等价于 `is_deep` 设置为 `True` 时的 `to_ref`
255
+
256
+ ---
257
+
258
+ ### `deep_ref`
259
+ 等价于 `is_deep` 设置为 `True` 时的 `to_ref`。
260
+
261
+ 当数据源为列表、字典或自定义类时,特别有用。通过 `.value` 获取的对象为代理对象
262
+ ```python
263
+ data = [1,2,3]
264
+ data_ref = deep_ref(data)
265
+
266
+ assert data_ref.value is not data
267
+ ```
268
+
269
+ 通过 `to_raw` 可以获取原始对象
270
+ ```python
271
+ from ex4nicegui import to_raw, deep_ref
272
+
273
+ data = [1, 2, 3]
274
+ data_ref = deep_ref(data)
275
+
276
+ assert data_ref.value is not data
277
+ assert to_raw(data_ref.value) is data
278
+ ```
279
+
280
+
281
+ ---
282
+
283
+ ### `effect`
284
+ 接受一个函数,自动监控函数中使用到的响应式对象变化,从而自动执行函数
285
+
286
+ ```python
287
+ a = to_ref(1)
288
+ b = to_ref("text")
289
+
290
+
291
+ @effect
292
+ def auto_run_when_ref_value():
293
+ print(f"a:{a.value}")
294
+
295
+
296
+ def change_value():
297
+ a.value = 2
298
+ b.value = "new text"
299
+
300
+
301
+ ui.button("change", on_click=change_value)
302
+ ```
303
+
304
+ 首次执行 effect ,函数`auto_run_when_ref_value`将被执行一次.之后点击按钮,改变 `a` 的值(通过 `a.value`),函数`auto_run_when_ref_value`再次执行
305
+
306
+ > 切忌把大量数据处理逻辑分散在多个 `on` 或 `effect` 中,`on` 或 `effect` 中应该大部分为界面操作逻辑,而非响应式数据处理逻辑
307
+
308
+ ---
309
+
310
+ ### `ref_computed`
311
+ 与 `effect` 具备一样的功能,`ref_computed` 还能从函数中返回结果。一般用于从 `to_ref` 中进行二次计算
312
+
313
+ ```python
314
+ a = to_ref(1)
315
+ a_square = ref_computed(lambda: a.value * 2)
316
+
317
+
318
+ @effect
319
+ def effect1():
320
+ print(f"a_square:{a_square.value}")
321
+
322
+
323
+ def change_value():
324
+ a.value = 2
325
+
326
+
327
+ ui.button("change", on_click=change_value)
328
+ ```
329
+
330
+ 点击按钮后,`a.value` 值被修改,从而触发 `a_square` 重新计算.由于 `effect1` 中读取了 `a_square` 的值,从而触发 `effect1` 执行
331
+
332
+ > `ref_computed` 是只读的 `to_ref`
333
+
334
+
335
+ 如果你更喜欢通过类组织代码,`ref_computed` 同样支持作用到实例方法上
336
+
337
+ ```python
338
+ class MyState:
339
+ def __init__(self) -> None:
340
+ self.r_text = to_ref("")
341
+
342
+ @ref_computed
343
+ def post_text(self):
344
+ return self.r_text.value + "post"
345
+
346
+ state = MyState()
347
+
348
+ rxui.input(value=state.r_text)
349
+ rxui.label(state.post_text)
350
+ ```
351
+
352
+ ---
353
+
354
+ ### `async_computed`
355
+ 二次计算中需要使用异步函数时,使用 `async_computed`
356
+ ```python
357
+
358
+ # 模拟长时间执行的异步函数
359
+ async def long_time_query(input: str):
360
+ await asyncio.sleep(2)
361
+ num = random.randint(20, 100)
362
+ return f"query result[{input=}]:{num=}"
363
+
364
+
365
+ search = to_ref("")
366
+ evaluating = to_ref(False)
367
+
368
+ @async_computed(search, evaluating=evaluating, init="")
369
+ async def search_result():
370
+ return await long_time_query(search.value)
371
+
372
+ rxui.lazy_input(value=search)
373
+
374
+ rxui.label(
375
+ lambda: "查询中" if evaluating.value else "上方输入框输入内容并回车搜索"
376
+ )
377
+ rxui.label(search_result)
378
+
379
+ ```
380
+
381
+ - `async_computed` 第一个参数必须明确指定需要监控的响应式数据. 使用列表可以同时指定多个响应式数据
382
+ - 参数 `evaluating` 为 bool 类型的响应式数据,当异步函数执行中,此变量值为 `True`,计算结束后为 `False`
383
+ - 参数 `init` 指定初始结果
384
+
385
+
386
+ ---
387
+
388
+ ### `on`
389
+ 类似 `effect` 的功能,但是 `on` 需要明确指定监控的响应式对象
390
+
391
+ ```python
392
+
393
+ a1 = to_ref(1)
394
+ a2 = to_ref(10)
395
+ b = to_ref("text")
396
+
397
+
398
+ @on(a1)
399
+ def watch_a1_only():
400
+ print(f"watch_a1_only ... a1:{a1.value},a2:{a2.value}")
401
+
402
+
403
+ @on([a1, b], onchanges=True)
404
+ def watch_a1_and_b():
405
+ print(f"watch_a1_and_b ... a1:{a1.value},a2:{a2.value},b:{b.value}")
406
+
407
+
408
+ def change_a1():
409
+ a1.value += 1
410
+ ui.notify("change_a1")
411
+
412
+
413
+ ui.button("change a1", on_click=change_a1)
414
+
415
+
416
+ def change_a2():
417
+ a2.value += 1
418
+ ui.notify("change_a2")
419
+
420
+
421
+ ui.button("change a2", on_click=change_a2)
422
+
423
+
424
+ def change_b():
425
+ b.value += "x"
426
+ ui.notify("change_b")
427
+
428
+
429
+ ui.button("change b", on_click=change_b)
430
+
431
+ ```
432
+
433
+ - 参数 `onchanges` 为 True 时(默认值为 False),指定的函数不会在绑定时执行
434
+
435
+
436
+ > 切忌把大量数据处理逻辑分散在多个 `on` 或 `effect` 中,`on` 或 `effect` 中应该大部分为界面操作逻辑,而非响应式数据处理逻辑
437
+
438
+ ---
439
+
440
+ ### `new_scope`
441
+
442
+ 默认情况下,所有检测函数在客户端连接断开时自动销毁。如果需要更细粒度的控制,可以使用 `new_scope`
443
+
444
+ ```python
445
+ from nicegui import ui
446
+ from ex4nicegui import rxui, to_ref, effect, new_scope
447
+
448
+ a = to_ref(0.0)
449
+
450
+ scope1 = new_scope()
451
+
452
+ @scope1.run
453
+ def _():
454
+ @effect
455
+ def _():
456
+ print(f"scope 1:{a.value}")
457
+
458
+
459
+ rxui.number(value=a)
460
+ rxui.button("dispose scope 1", on_click=scope1.dispose)
461
+ ```
462
+
463
+ ---
464
+
465
+
466
+ ## 组件功能
467
+
468
+ ### vmodel
469
+ 在表单输入元素或组件上创建双向绑定。
470
+
471
+ 简单值类型的 `ref` 默认支持双向绑定
472
+ ```python
473
+ from ex4nicegui import rxui, to_ref, deep_ref
474
+
475
+ data = to_ref("init")
476
+
477
+ rxui.label(lambda: f"{data.value=}")
478
+ # 默认就是双向绑定
479
+ rxui.input(value=data)
480
+ ```
481
+
482
+ - 简单值类型一般是 `str`,`int` 等不可变值类型
483
+
484
+ 当使用复杂数据结构时,会使用 `deep_ref` 保持嵌套值的响应性
485
+ ```python
486
+ data = deep_ref({"a": 1, "b": [1, 2, 3, 4]})
487
+
488
+ rxui.label(lambda: f"{data.value=!s}")
489
+
490
+ # 当前版本没有任何绑定效果.或许未来的版本可以解决
491
+ rxui.input(value=data.value["a"])
492
+
493
+ # 只读绑定.其他途径修改了 `data.value["a"]` ,此输入框会同步,但反过来不行
494
+ rxui.input(value=lambda: data.value["a"])
495
+
496
+ # 要使用 vmodel 才能双向绑定
497
+ rxui.input(value=rxui.vmodel(data.value["a"]))
498
+ ```
499
+
500
+ - 第一个输入框将完全失去响应性,因为代码等价于直接传入一个数值`1`
501
+ - 第二个输入框由于使用函数,将得到读取响应性(第三个输入框输入值,将得到同步)
502
+ - 第三个输入框,使用 `rxui.vmodel` 包裹,即可实现双向绑定
503
+
504
+ 多数在配合 `vfor` 时使用 `vmodel`,可参考 [todo list 案例](./examples/todomvc/)
505
+
506
+
507
+ ### vfor
508
+ 基于列表响应式数据,渲染列表组件。每项组件按需更新。数据项支持字典或任意类型对象
509
+
510
+ ```python
511
+ from nicegui import ui
512
+ from ex4nicegui.reactive import rxui
513
+ from ex4nicegui import deep_ref, ref_computed
514
+ from typing import Dict
515
+
516
+ # refs
517
+ items = deep_ref(
518
+ [
519
+ {"id": 1, "message": "foo", "done": False},
520
+ {"id": 2, "message": "bar", "done": True},
521
+ ]
522
+ )
523
+
524
+ # ref_computeds
525
+ @ref_computed
526
+ def done_count_info():
527
+ return f"done count:{sum(item['done'] for item in items.value)}"
528
+
529
+ # method
530
+ def check():
531
+ for item in items.value:
532
+ item["done"] = not item["done"]
533
+
534
+
535
+ # ui
536
+ rxui.label(done_count_info)
537
+ ui.button("check", on_click=check)
538
+
539
+
540
+ @rxui.vfor(items,key='id')
541
+ def _(store: rxui.VforStore[Dict]):
542
+ # 函数中构建每一行数据的界面
543
+ item = store.get() # 通过 store.get 获取对应行的响应式对象(相当于每行的数据 to_ref(...))
544
+ mes = rxui.vmodel(item.value['message']) # 复杂结构默认没有双向绑定,需要使用 `vmodel`
545
+
546
+ # 输入框输入内容,可以看到单选框的标题同步变化
547
+ with ui.card():
548
+ with ui.row():
549
+ rxui.input(value=mes)
550
+ rxui.label(lambda: f"{mes.value=!s}")
551
+ rxui.checkbox(text=mes, value=rxui.vmodel(item.value['done']))
552
+
553
+ ```
554
+
555
+ - `rxui.vfor` 装饰器到自定义函数
556
+ - 第一个参数传入响应式列表。列表中每一项可以是字典或其他对象(`dataclasses` 等等)
557
+ - 第二个参数 `key`: 为了可以跟踪每个节点的标识,从而重用和重新排序现有的元素,你可以为每个元素对应的块提供一个唯一的 key 。默认情况使用列表元素索引。
558
+ - 自定义函数带有一个参数。通过 `store.get` 可以获取当前行的响应式对象
559
+
560
+ > vfor 渲染的项目,只有在新增数据时,才会创建
561
+
562
+
563
+ ---
564
+
565
+ ### 绑定类名
566
+
567
+ 所有的组件类提供 `bind_classes` 用于绑定 `class`,支持三种不同的数据结构。
568
+
569
+ 绑定字典
570
+
571
+ ```python
572
+ bg_color = to_ref(False)
573
+ has_error = to_ref(False)
574
+
575
+ rxui.label("test").bind_classes({"bg-blue": bg_color, "text-red": has_error})
576
+
577
+ rxui.switch("bg_color", value=bg_color)
578
+ rxui.switch("has_error", value=has_error)
579
+ ```
580
+
581
+ 字典键值为类名,对应值为 bool 的响应式变量。当响应式值为 `True`,类名应用到组件 class
582
+
583
+
584
+ ---
585
+
586
+ 绑定返回值为字典的响应式变量
587
+
588
+ ```python
589
+ bg_color = to_ref(False)
590
+ has_error = to_ref(False)
591
+
592
+ class_obj = ref_computed(
593
+ lambda: {"bg-blue": bg_color.value, "text-red": has_error.value}
594
+ )
595
+
596
+ rxui.switch("bg_color", value=bg_color)
597
+ rxui.switch("has_error", value=has_error)
598
+ rxui.label("bind to ref_computed").bind_classes(class_obj)
599
+ # or direct function passing
600
+ rxui.label("bind to ref_computed").bind_classes(
601
+ lambda: {"bg-blue": bg_color.value, "text-red": has_error.value}
602
+ )
603
+ ```
604
+
605
+ ---
606
+
607
+ 绑定为列表
608
+
609
+ ```python
610
+ bg_color = to_ref("red")
611
+ bg_color_class = ref_computed(lambda: f"bg-{bg_color.value}")
612
+
613
+ text_color = to_ref("green")
614
+ text_color_class = ref_computed(lambda: f"text-{text_color.value}")
615
+
616
+ rxui.select(["red", "green", "yellow"], label="bg color", value=bg_color)
617
+ rxui.select(["red", "green", "yellow"], label="text color", value=text_color)
618
+
619
+ rxui.label("binding to arrays").bind_classes([bg_color_class, text_color_class])
620
+
621
+ ```
622
+
623
+ 列表中每个元素为返回类名的响应式变量
624
+
625
+ ---
626
+
627
+ ### bind-style
628
+
629
+ ```python
630
+ from nicegui import ui
631
+ from ex4nicegui.reactive import rxui
632
+ from ex4nicegui.utils.signals import to_ref
633
+
634
+
635
+ bg_color = to_ref("blue")
636
+ text_color = to_ref("red")
637
+
638
+ rxui.label("test").bind_style(
639
+ {
640
+ "background-color": bg_color,
641
+ "color": text_color,
642
+ }
643
+ )
644
+
645
+ rxui.select(["blue", "green", "yellow"], label="bg color", value=bg_color)
646
+ rxui.select(["red", "green", "yellow"], label="text color", value=text_color)
647
+ ```
648
+
649
+ `bind_style` 传入字典,`key` 为样式名字,`value` 为样式值,响应式字符串
650
+
651
+ ---
652
+
653
+ ### bind_prop
654
+
655
+ 绑定单个属性
656
+
657
+ ```python
658
+
659
+ label = to_ref("hello")
660
+
661
+ rxui.button("").bind_prop("label", label)
662
+ # 允许使用函数
663
+ rxui.button("").bind_prop(
664
+ "label", lambda: f"{label.value} world"
665
+ )
666
+
667
+ rxui.input(value=label)
668
+ ```
669
+
670
+
671
+ ---
672
+
673
+ ### rxui.echarts
674
+ 使用 echarts 制作图表
675
+
676
+ ---
677
+
678
+ #### rxui.echarts.from_javascript
679
+ javascript 代码创建 echart
680
+
681
+ ```python
682
+ from pathlib import Path
683
+
684
+ rxui.echarts.from_javascript(Path("code.js"))
685
+ # or
686
+ rxui.echarts.from_javascript(
687
+ """
688
+ (myChart) => {
689
+
690
+ option = {
691
+ xAxis: {
692
+ type: 'category',
693
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
694
+ },
695
+ yAxis: {
696
+ type: 'value'
697
+ },
698
+ series: [
699
+ {
700
+ data: [120, 200, 150, 80, 70, 110, 130],
701
+ type: 'bar'
702
+ }
703
+ ]
704
+ };
705
+
706
+ myChart.setOption(option);
707
+ }
708
+ """
709
+ )
710
+ ```
711
+
712
+ - 函数第一个参数为 echart 实例对象.你需要在函数中通过 `setOption` 完成图表配置
713
+
714
+ 函数也有第二个参数,为 `echarts` 全局对象,你可以通过 `echarts.registerMap` 注册地图。
715
+
716
+ ```python
717
+ rxui.echarts.from_javascript(
718
+ """
719
+ (chart,echarts) =>{
720
+
721
+ fetch('https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json')
722
+ .then(response => response.json())
723
+ .then(data => {
724
+ echarts.registerMap('test_map', data);
725
+
726
+ chart.setOption({
727
+ geo: {
728
+ map: 'test_map',
729
+ roam: true,
730
+ },
731
+ tooltip: {},
732
+ legend: {},
733
+ series: [],
734
+ });
735
+ });
736
+ }
737
+ """
738
+ )
739
+ ```
740
+
741
+ ---
742
+
743
+ #### rxui.echarts.register_map
744
+ 注册地图.
745
+
746
+ ```python
747
+ rxui.echarts.register_map(
748
+ "china", "https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json"
749
+ )
750
+
751
+ rxui.echarts(
752
+ {
753
+ "geo": {
754
+ "map": "china",
755
+ "roam": True,
756
+ },
757
+ "tooltip": {},
758
+ "legend": {},
759
+ "series": [],
760
+ }
761
+ )
762
+ ```
763
+
764
+ - 参数 `map_name` 为自定义的地图名字。注意在图表配置中 `map` 必需对应注册的名字
765
+ - 参数 `src` 为有效的地图数据网络链接。
766
+
767
+
768
+ 如果是 svg 数据,需要设置参数 `type="svg"`
769
+ ```python
770
+ rxui.echarts.register_map("svg-rect", "/test/svg", type="svg")
771
+ ```
772
+
773
+
774
+
775
+ 你也可以直接提供本地地图数据的json文件路径对象(Path)
776
+ ```python
777
+ from pathlib import Path
778
+
779
+ rxui.echarts.register_map(
780
+ "china", Path("map-data.json")
781
+ )
782
+ ```
783
+
784
+ ---
785
+
786
+ ### gsap
787
+ js 动画库. [gsap文档](https://gsap.com/docs/v3/)
788
+
789
+ ```python
790
+ from nicegui import ui
791
+ from ex4nicegui import gsap
792
+ ```
793
+
794
+ #### gsap.from_
795
+
796
+ 设置起始属性,动画将从设置的属性过渡到原始位置
797
+
798
+ ```python
799
+
800
+ ui.label("test from").classes("target")
801
+ gsap.from_(".target", {"x": 50,'duration':1})
802
+
803
+ ```
804
+
805
+ 画面加载后,文本起始位置在往右偏移 50px 处,在 1秒 内移动到原始位置上
806
+
807
+ - 参数 `targets` 为 css 选择器
808
+ - 参数 `vars` 为属性值,具体参考 gsap 文档
809
+
810
+ ---
811
+
812
+ #### gsap.to
813
+
814
+ 设置结束属性,动画将从原始属性过渡到设置的属性
815
+
816
+ ```python
817
+
818
+ ui.label("test to").classes("target")
819
+ gsap.to(".target", {"x": 50,'duration':1})
820
+
821
+ ```
822
+
823
+ 画面加载后,文本在 1秒 内,从原始位置往后移动 50px
824
+
825
+ - 参数 `targets` 为 css 选择器
826
+ - 参数 `vars` 为属性值,具体参考 gsap 文档
827
+
828
+ ---
829
+ #### gsap.run_script
830
+
831
+ 通过编写 js 设置动画
832
+
833
+ ```python
834
+
835
+ gsap.run_script(
836
+ r"""function setGsap(gsap) {
837
+ gsap.to('.target',{"duration": 0.3,y:60})
838
+ }
839
+ """)
840
+ ```
841
+
842
+ - 参数 `script` 可以为文本或 js 后缀的文件 `Path`
843
+ - 定义的 js 函数名字并不影响运行,第一个参数为 gsap 对象
844
+
845
+ ---
846
+
847
+ ### tab_panels
848
+
849
+ 相比较于 `nicegui.ui.tab_panels` , `rxui.tab_panels` 没有参数 `tabs`。在数据响应式机制下,`tabs` 与 `tab_panels` 联动只需要通过参数 `value` 即可。
850
+
851
+ ```python
852
+ from nicegui import ui
853
+ from ex4nicegui import rxui, to_ref
854
+
855
+ names = ["Tab 1", "Tab 2", "Tab 3"]
856
+ current_tab = to_ref(names[0])
857
+
858
+ with rxui.tabs(current_tab):
859
+ for name in names:
860
+ rxui.tab(name)
861
+
862
+ with rxui.tab_panels(current_tab):
863
+ for name in names:
864
+ with rxui.tab_panel(name):
865
+ ui.label(f"Content of {name}")
866
+ ```
867
+
868
+ 这是因为,数据响应机制下,组件联动是通过中间数据层(`to_ref`)实现的。因此,`tab_panels` 可以与其他组件联动(只需要保证使用同样的 `ref` 对象即可)
869
+
870
+ ```python
871
+ names = ["Tab 1", "Tab 2", "Tab 3"]
872
+ current_tab = to_ref(names[0])
873
+
874
+
875
+ with rxui.tab_panels(current_tab):
876
+ for name in names:
877
+ with rxui.tab_panel(name):
878
+ ui.label(f"Content of {name}")
879
+
880
+ # tabs 不必在 panels 前面
881
+ with rxui.tabs(current_tab):
882
+ for name in names:
883
+ rxui.tab(name)
884
+
885
+ rxui.select(names, value=current_tab)
886
+ rxui.radio(names, value=current_tab).props("inline")
887
+
888
+ rxui.label(lambda: f"当前 tab 为:{current_tab.value}")
889
+ ```
890
+
891
+
892
+ ---
893
+
894
+ ## BI 模块
895
+
896
+ 以最精简的 apis 创建可交互的数据可视化报表
897
+
898
+ ![](./asset/bi_examples1.gif)
899
+
900
+ ```python
901
+ from nicegui import ui
902
+ import pandas as pd
903
+ import numpy as np
904
+ from ex4nicegui import bi
905
+ from ex4nicegui.reactive import rxui
906
+ from ex4nicegui import effect, effect_refreshable
907
+ from pyecharts.charts import Bar
908
+
909
+
910
+ # data ready
911
+ def gen_data():
912
+ np.random.seed(265)
913
+ field1 = ["a1", "a2", "a3", "a4"]
914
+ field2 = [f"name{i}" for i in range(1, 11)]
915
+ df = (
916
+ pd.MultiIndex.from_product([field1, field2], names=["cat", "name"])
917
+ .to_frame()
918
+ .reset_index(drop=True)
919
+ )
920
+ df[["idc1", "idc2"]] = np.random.randint(50, 1000, size=(len(df), 2))
921
+ return df
922
+
923
+
924
+ df = gen_data()
925
+
926
+ # 创建数据源
927
+ ds = bi.data_source(df)
928
+
929
+ # ui
930
+ ui.query(".nicegui-content").classes("items-stretch no-wrap")
931
+
932
+ with ui.row().classes("justify-evenly"):
933
+ # 基于数据源 `ds` 创建界面组件
934
+ ds.ui_select("cat").classes("min-w-[10rem]")
935
+ ds.ui_select("name").classes("min-w-[10rem]")
936
+
937
+
938
+ with ui.grid(columns=2):
939
+ # 使用字典配置图表
940
+ @ds.ui_echarts
941
+ def bar1(data: pd.DataFrame):
942
+ data = data.groupby("name").agg({"idc1": "sum", "idc2": "sum"}).reset_index()
943
+
944
+ return {
945
+ "xAxis": {"type": "value"},
946
+ "yAxis": {
947
+ "type": "category",
948
+ "data": data["name"].tolist(),
949
+ "inverse": True,
950
+ },
951
+ "legend": {"textStyle": {"color": "gray"}},
952
+ "series": [
953
+ {"type": "bar", "name": "idc1", "data": data["idc1"].tolist()},
954
+ {"type": "bar", "name": "idc2", "data": data["idc2"].tolist()},
955
+ ],
956
+ }
957
+
958
+ bar1.classes("h-[20rem]")
959
+
960
+ # 使用pyecharts配置图表
961
+ @ds.ui_echarts
962
+ def bar2(data: pd.DataFrame):
963
+ data = data.groupby("name").agg({"idc1": "sum", "idc2": "sum"}).reset_index()
964
+
965
+ return (
966
+ Bar()
967
+ .add_xaxis(data["name"].tolist())
968
+ .add_yaxis("idc1", data["idc1"].tolist())
969
+ .add_yaxis("idc2", data["idc2"].tolist())
970
+ )
971
+
972
+ bar2.classes("h-[20rem]")
973
+
974
+ # 绑定点击事件,即可实现跳转
975
+ @bar2.on_chart_click
976
+ def _(e: rxui.echarts.EChartsMouseEventArguments):
977
+ ui.open(f"/details/{e.name}", new_tab=True)
978
+
979
+
980
+ # 利用响应式机制,你可以随意组合原生 nicegui 组件
981
+ label_a1_total = ui.label("")
982
+
983
+
984
+ # 当 ds 有变化,都会触发此函数
985
+ @effect
986
+ def _():
987
+ # filtered_data 为过滤后的 DataFrame
988
+ df = ds.filtered_data
989
+ total = df[df["cat"] == "a1"]["idc1"].sum()
990
+ label_a1_total.text = f"idc1 total(cat==a1):{total}"
991
+
992
+
993
+ # 你也可以使用 `effect_refreshable`,但需要注意函数中的组件每次都被重建
994
+ @effect_refreshable
995
+ def _():
996
+ df = ds.filtered_data
997
+ total = df[df["cat"] == "a2"]["idc1"].sum()
998
+ ui.label(f"idc1 total(cat==a2):{total}")
999
+
1000
+
1001
+ # 当点击图表系列时,跳转的页面
1002
+ @ui.page("/details/{name}")
1003
+ def details_page(name: str):
1004
+ ui.label("This table data will not change")
1005
+ ui.aggrid.from_pandas(ds.data.query(f'name=="{name}"'))
1006
+
1007
+ ui.label("This table will change when the homepage data changes. ")
1008
+
1009
+ @bi.data_source
1010
+ def new_ds():
1011
+ return ds.filtered_data[["name", "idc1", "idc2"]]
1012
+
1013
+ new_ds.ui_aggrid()
1014
+
1015
+
1016
+ ui.run()
1017
+ ```
1018
+
1019
+
1020
+
1021
+ ### 细节
1022
+
1023
+
1024
+
1025
+
1026
+ #### `bi.data_source`
1027
+ 数据源是 BI 模块的核心概念,所有数据的联动基于此展开。当前版本(0.4.3)中,有两种创建数据源的方式
1028
+
1029
+ 接收 `pandas` 的 `DataFrame`:
1030
+ ```python
1031
+ from nicegui import ui
1032
+ from ex4nicegui import bi
1033
+ import pandas as pd
1034
+
1035
+ df = pd.DataFrame(
1036
+ {
1037
+ "name": list("aabcdf"),
1038
+ "cls": ["c1", "c2", "c1", "c1", "c3", None],
1039
+ "value": range(6),
1040
+ }
1041
+ )
1042
+
1043
+ ds = bi.data_source(df)
1044
+ ```
1045
+
1046
+ ---
1047
+ 有时候,我们希望基于另一个数据源创建新的数据源,此时可以使用装饰器创建联动数据源:
1048
+ ```python
1049
+ df = pd.DataFrame(
1050
+ {
1051
+ "name": list("aabcdf"),
1052
+ "cls": ["c1", "c2", "c1", "c1", "c3", None],
1053
+ "value": range(6),
1054
+ }
1055
+ )
1056
+
1057
+ ds = bi.data_source(df)
1058
+
1059
+ @bi.data_source
1060
+ def new_ds():
1061
+ # df is pd.DataFrame
1062
+ df = ds.filtered_data
1063
+ df=df.copy()
1064
+ df['value'] = df['value'] * 100
1065
+ return df
1066
+
1067
+ ds.ui_select('name')
1068
+ new_ds.ui_aggrid()
1069
+
1070
+ ```
1071
+
1072
+ 注意,由于 `new_ds` 中使用了 `ds.filtered_data` ,因此 `ds` 的变动会触发 `new_ds` 的联动变化,从而导致 `new_ds` 创建的表格组件产生变化
1073
+
1074
+ ---
1075
+ 通过 `ds.remove_filters` 方法,移除所有筛选状态:
1076
+ ```python
1077
+ ds = bi.data_source(df)
1078
+
1079
+ def on_remove_filters():
1080
+ ds.remove_filters()
1081
+
1082
+ ui.button("remove all filters", on_click=on_remove_filters)
1083
+
1084
+ ds.ui_select("name")
1085
+ ds.ui_aggrid()
1086
+ ```
1087
+ ---
1088
+
1089
+ 通过 `ds.reload` 方法,重设数据源:
1090
+ ```python
1091
+
1092
+ df = pd.DataFrame(
1093
+ {
1094
+ "name": list("aabcdf"),
1095
+ "cls": ["c1", "c2", "c1", "c1", "c3", None],
1096
+ "value": range(6),
1097
+ }
1098
+ )
1099
+
1100
+ new_df = pd.DataFrame(
1101
+ {
1102
+ "name": list("xxyyds"),
1103
+ "cls": ["cla1", "cla2", "cla3", "cla3", "cla3", None],
1104
+ "value": range(100, 106),
1105
+ }
1106
+ )
1107
+
1108
+ ds = bi.data_source(df)
1109
+
1110
+ def on_remove_filters():
1111
+ ds.reload(new_df)
1112
+
1113
+ ui.button("reload data", on_click=on_remove_filters)
1114
+
1115
+ ds.ui_select("name")
1116
+ ds.ui_aggrid()
1117
+ ```
1118
+
1119
+ ---
1120
+ #### ui_select
1121
+
1122
+ ```python
1123
+ from nicegui import ui
1124
+ from ex4nicegui import bi
1125
+ import pandas as pd
1126
+
1127
+ df = pd.DataFrame(
1128
+ {
1129
+ "name": list("aabcdf"),
1130
+ "cls": ["c1", "c2", "c1", "c1", "c3", None],
1131
+ "value": range(6),
1132
+ }
1133
+ )
1134
+
1135
+ ds = bi.data_source(df)
1136
+
1137
+ ds.ui_select("name")
1138
+ ```
1139
+
1140
+ 第一个参数 column 指定数据源的列名
1141
+
1142
+ ---
1143
+ 通过参数 `sort_options` 设置选项顺序:
1144
+ ```python
1145
+ ds.ui_select("name", sort_options={"value": "desc", "name": "asc"})
1146
+
1147
+ ```
1148
+
1149
+ ---
1150
+ 参数 `exclude_null_value` 设置是否排除空值:
1151
+ ```python
1152
+ df = pd.DataFrame(
1153
+ {
1154
+ "cls": ["c1", "c2", "c1", "c1", "c3", None],
1155
+ }
1156
+ )
1157
+
1158
+ ds = bi.data_source(df)
1159
+ ds.ui_select("cls", exclude_null_value=True)
1160
+ ```
1161
+
1162
+ ---
1163
+
1164
+ 你可以通过关键字参数,设置原生 nicegui select 组件的参数.
1165
+
1166
+ 通过 value 属性,设置默认值:
1167
+ ```python
1168
+ ds.ui_select("cls",value=['c1','c2'])
1169
+ ds.ui_select("cls",multiple=False,value='c1')
1170
+
1171
+ ```
1172
+
1173
+ 多选时(参数 `multiple` 默认为 True),`value` 需要指定为 list
1174
+
1175
+ 单选时,`value` 设置为非 list
1176
+
1177
+ ---
1178
+
1179
+ #### ui_table
1180
+
1181
+ 表格
1182
+
1183
+ ```python
1184
+ from nicegui import ui
1185
+ from ex4nicegui import bi
1186
+ import pandas as pd
1187
+
1188
+ data = pd.DataFrame({"name": ["f", "a", "c", "b"], "age": [1, 2, 3, 1]})
1189
+ ds = bi.data_source(data)
1190
+
1191
+ ds.ui_table(
1192
+ columns=[
1193
+ {"label": "new colA", "field": "colA", "sortable": True},
1194
+ ]
1195
+ )
1196
+
1197
+ ```
1198
+
1199
+ - columns 与 nicegui `ui.table` 一致。其中 键值 `field` 对应数据源的列名,如果不存在,则该配置不会生效
1200
+ - rows 参数不会生效。因为表格的数据源始终由 data source 控制
1201
+
1202
+ ---
1203
+
1204
+ #### ui_aggrid
1205
+
1206
+
1207
+ ```python
1208
+ from nicegui import ui
1209
+ from ex4nicegui import bi
1210
+ import pandas as pd
1211
+
1212
+ data = pd.DataFrame(
1213
+ {
1214
+ "colA": list("abcde"),
1215
+ "colB": [f"n{idx}" for idx in range(5)],
1216
+ "colC": list(range(5)),
1217
+ }
1218
+ )
1219
+ df = pd.DataFrame(data)
1220
+
1221
+ source = bi.data_source(df)
1222
+
1223
+ source.ui_aggrid(
1224
+ options={
1225
+ "columnDefs": [
1226
+ {"headerName": "xx", "field": "no exists"},
1227
+ {"headerName": "new colA", "field": "colA"},
1228
+ {
1229
+ "field": "colC",
1230
+ "cellClassRules": {
1231
+ "bg-red-300": "x < 3",
1232
+ "bg-green-300": "x >= 3",
1233
+ },
1234
+ },
1235
+ ],
1236
+ "rowData": [{"colX": [1, 2, 3, 4, 5]}],
1237
+ }
1238
+ )
1239
+ ```
1240
+
1241
+ - 参数 options 与 nicegui `ui.aggrid` 一致。其中 `columnDefs` 中的键值 `field` 对应数据源的列名,如果不存在,则该配置不会生效
1242
+ - `rowData` 键值不会生效。因为表格的数据源始终由 data source 控制
1243
+
1244
+
1245
+