You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shiny Express中expressify下依赖输入的计算结果不显示问题求助

问题解决:拆分Shiny应用后render.express无法显示结果

问题原因

你在page.py中仅定义了@render.express装饰的text_to_display函数,但未在UI上下文里调用该函数,导致渲染结果没有被添加到页面的UI树中,因此无法显示输出内容。

修改方案

修改page.py,在输入组件后调用text_to_display(),将渲染结果挂载到UI中:

from shiny import render
from shiny.express import input, ui, expressify

@expressify
def otherNav():
    with ui.nav_panel("Page I want to put in the main app", value="other_page"):
        ui.input_numeric("input_value", "I need this input value!", 1, min=1, max=1000)
        @render.express
        def text_to_display():
            x = input.input_value()
            x
        # 调用渲染函数,将计算结果添加到页面
        text_to_display()

原理说明

在Shiny Express的声明式语法中,@render.express装饰的函数本质是一个动态UI生成器,必须通过调用它才能将其输出插入到当前的UI上下文里。仅定义函数不会自动触发渲染,添加调用后,Shiny会自动监听input_value的变化,实时更新并显示计算结果。

内容的提问来源于stack exchange,提问作者Redz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 20:35:13