Skip to content

Passing environment variables at the CLI for shinyapps.io #437

Closed

Description

@phobson

Hey folks,

I'm stumped here. It looks like rsconnect-python isn't passing environment variables to shinyapps.io

Perhaps this is a limitation of shinyapps and I'm not picking that up from the docs. Here's what I'm looking: https://github.com/rstudio/rsconnect-python#environment-variables

Here's my app.py:

from shiny import App, render, ui
import os

app_ui = ui.page_fluid(
    ui.h2("Reading Environment Variables When Deployed"),
    ui.input_slider("n", "N", 1, 10, 1),
    ui.output_text_verbatim("txt"),
)


def server(input, output, session):
    @output
    @render.text
    def txt():
        var = os.environ.get("MYENVVAR", "FAIL")
        return "-".join([var for _ in range(input.n())])


app = App(app_ui, server)

And then from a terminal, I do:

export MYENVVAR=Successful
python -m shiny run --port 45937 --reload "/home/paul/sources/envvar-test/app.py"

And I get:
image

But when it's time to deploy:

rsconnect write-manifest shiny . --entrypoint=app.py --overwrite --exclude=__pycache__
rsconnect deploy manifest manifest.json --name <server> --title envvartest --environment MYENVVAR='Success'

I get:

image

I also tried:

# no quotes
rsconnect deploy manifest manifest.json --name <server>--title envvartest --environment MYENVVAR=Success

# and bare var name
export MYENVVAR=Successful
rsconnect deploy manifest manifest.json --name <server> --title envvartest --environment MYENVVAR


# and short -E flag
export MYENVVAR=Successful
rsconnect deploy manifest manifest.json --name <server>--title envvartest -E MYENVVAR

But got the same result each time.

Should this work?

Activity

  1. aronatkins commented on Jun 30, 2023

    @aronatkins
    Collaborator

    shinyapps.io does not permit environment variable management like you describe.

    The rsconnect-python documentation should indicate that environment variables are a Connect-only feature.

  2. phobson commented on Jun 30, 2023

    @phobson
    ContributorAuthor

    @aronatkins thanks for the quick reply. I proposed a small change to (maybe) help clarify this.

    I'm new to the shiny ecosystem, so this nuance might be obvious to most people. No hard feelings if the PR is rejected. I think this issue can be closed with or without the PR.

    I'm loving python-shiny and rsconnect in either case.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions