H2O WAVE 01 Hello World
前言
在本节中,我们将学习如何从头开始编写我们的第一个Wave程序,并了解如何在web浏览器中显示内容的基本知识。
一、启动Wave服务器
下载操作系统的最新版本.tar.gz文件,并将其解压缩到您选择的目录中。完成后,打开一个终端,cd到提取的目录中,然后启动Wave服务器。
./waved
*不要关闭这个终端窗口!
要运行任何Wave应用程序或脚本,您需要随时启动并运行Wave服务器。您的web浏览器与Wave服务器通信,而Wave服务器又与Wave应用程序通信。
应用程序可以通过Wave run命令自动启动Wave服务器。因此,此步骤仅对Wave脚本是必需的。*
二、设置工作目录
设置一个工作目录来编写我们的程序。创建一个新目录并在终端中打开它。
设置虚拟环境
虚拟环境可以帮助我们管理程序的依赖关系,而不会干扰系统范围的程序包。
python3 -m venv venv
source venv/bin/activate
pip install h2o-wave
三、编写程序
打开您喜欢的文本编辑器,创建一个名为hello_world.py的Python脚本,然后复制粘贴以下内容。
from h2o_wave import site, ui
# Grab a reference to the page at route '/hello'
page = site['/hello']
# Add a markdown card to the page.
page['quote'] = ui.markdown_card(
box='1 1 2 2',
title='Hello World',
content='"The Internet? Is that thing still around?" - *Homer Simpson*',
)
# Finally, save the page.
page.save()
四、运行程序
python hello_world.py
将浏览器指向http://localhost:10101/hello