在AWS Lambda函数中,Bokeh图的输出位置可以有多种方式。以下是几种常见的解决方法:
from bokeh.plotting import figure, output_file, save
def lambda_handler(event, context):
# 创建Bokeh图
p = figure(title="My Bokeh Plot")
p.circle([1, 2, 3], [4, 5, 6])
# 设置输出文件位置
output_file('/tmp/bokeh_plot.png')
# 保存Bokeh图为PNG文件
save(p)
# 将图像文件上传到S3存储桶
s3_client = boto3.client('s3')
s3_client.upload_file('/tmp/bokeh_plot.png', 'my-s3-bucket', 'bokeh_plots/bokeh_plot.png')
return {
'statusCode': 200,
'body': 'Bokeh plot saved and uploaded successfully!'
}
from bokeh.plotting import figure, output_file, save
def lambda_handler(event, context):
# 创建Bokeh图
p = figure(title="My Bokeh Plot")
p.circle([1, 2, 3], [4, 5, 6])
# 设置输出文件位置
output_file('/tmp/bokeh_plot.html')
# 保存Bokeh图为HTML文件
save(p)
# 将HTML文件上传到S3存储桶
s3_client = boto3.client('s3')
s3_client.upload_file('/tmp/bokeh_plot.html', 'my-s3-bucket', 'bokeh_plots/bokeh_plot.html')
return {
'statusCode': 200,
'body': 'Bokeh plot saved and uploaded successfully!'
}
from bokeh.plotting import figure
from bokeh.embed import components
def lambda_handler(event, context):
# 创建Bokeh图
p = figure(title="My Bokeh Plot")
p.circle([1, 2, 3], [4, 5, 6])
# 获取Bokeh图的HTML和JS代码
script, div = components(p)
# 将HTML和JS代码作为Lambda函数的响应返回
return {
'statusCode': 200,
'body': {
'html': div,
'script': script
}
}
以上是几种常见的解决方法,根据具体需求选择适合的方式。