Giter Club home page Giter Club logo

Comments (2)

wch avatar wch commented on July 18, 2024 1

It looks like that error message needs to be fixed.

An explanation of what's happening:

  • With Shiny Express apps, the code in the .py file is run once at startup to generate the UI (which is saved and served each time someone connects), and once for each new user session.
  • For the first, UI-generating pass, the shiny.express.session is not a real Session object, but instead a ExpressMockSession object. This is the object which throws errors when you try to access the .id member.
  • For the user sessions, shiny.express.session is a Sesssion object, and accessing members of it will work fine.

I think it would make sense to add a method to ExpressMockSession and Session, which reports whether it is a real session object.

For the moment your workaround should be OK. Or you can use this, which is slightly less hacky:

from shiny.session import Session
from shiny.express import session

if isinstance(session, Session):
    print("The session ID is:" + str(session.id))

from py-shiny.

wch avatar wch commented on July 18, 2024 1

In #1331, we added a new method .is_stub_session(). So with the development version of shiny, you should be able to do:

from shiny.express import session

if not session.is_stub_session():
    print("The session ID is:" + str(session.id))

from py-shiny.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.