Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@reactive.event cause RuntimeError: shiny.express.input can only be used inside of a Shiny Express app. #1741

Open
wdesaintjean opened this issue Oct 22, 2024 · 2 comments

Comments

@wdesaintjean
Copy link

Hello
I wrote an app in shiny express python, and its worked well in a local server on my computer. But when I try to install my app on a server, (with a docker image, and irequired python packages), I have an error that said:

Traceback (most recent call last):
  File "/home/app/app.py", line 197, in <module>
    @reactive.event(input.action_button)
  File "/usr/local/lib/python3.10/site-packages/shiny/express/__init__.py", line 76, in __getattr__
    raise RuntimeError(
RuntimeError: shiny.express.input can only be used inside of a Shiny Express app.

It seems to not accept the utilization of @reactive.event() in a shiny express application, but I saw in the documentation that the reactive module is unchanged between Core and Express. I don't understand the problem. Here the problematic part of my code:

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

ui.panel_title("Exploration of Nanopore RNAseq results")

ui.input_text("gene_name", "Gene name Symbol", "Enter gene")   

ui.input_action_button("action_button", "Search", disabled=False)

@render.text 
@reactive.event(input.action_button)
def txt():

    gene_conv=pl.read_csv("./data/geneToSymbol_GRCm38.99.csv", separator="\t", has_header = False)
    if input.gene_name() in gene_conv['column_2']:
        return f"The chosen gene is {input.gene_name()}"
    else: 
        return f"The gene symbol is not in mm10 reference"

What's bug me is that worked perfectly fine on my computer with manual import of python packages.
I suppose I can always convert my code in Shiny Core python, but it will be a lot of works, I will gain a lot of time if It 's only a little mistake.

Can you help me?

@GiorgioMiglia
Copy link

GiorgioMiglia commented Oct 25, 2024

I ran your code in a devcontainer with Python 3.12.4 and Shiny, and it worked without any issues. This suggests the problem might not be with this snippet specifically, but rather with the overall structure of your code.

My test:
App.py

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

ui.panel_title("Exploration of Nanopore RNAseq results")

ui.input_text("gene_name", "Gene name Symbol", "Enter gene")   

ui.input_action_button("action_button", "Search", disabled=False)

@render.text 
@reactive.event(input.action_button)
def txt():

    #gene_conv=pl.read_csv("./data/geneToSymbol_GRCm38.99.csv", separator="\t", has_header = False)
    if input.gene_name() in ['ok', 'ok2']:
        return f"The chosen gene is {input.gene_name()}"
    else: 
        return f"The gene symbol is not in mm10 reference"

devcontainer.json

{
    "name": "test",
    "build": {
      "dockerfile": "Dockerfile",
      "context": ".."
    },
    "customizations": {
    "vscode": {
      "extensions": [
    	  "ms-python.python",
        "Posit.shiny",
        "ms-azuretools.vscode-docker",
    	],
      "settings": {"python.defaultInterpreterPath": "/usr/local/bin/python"}
    }
  }
  }

Dockerfile:

FROM python:3.12.4


RUN apt-get -y update && apt-get -y upgrade

WORKDIR /

RUN pip install shiny

COPY . .

@wdesaintjean
Copy link
Author

wdesaintjean commented Oct 28, 2024

Thank you for your answer,
I rewrite my code only in shiny core and its working. The problem can came from our installation on the server or from the python version used ( 3.10) I will investigate.

Thank you again for testing my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants