Skip to content

Commit 5b2db2a

Browse files
committed
Revamp is_hosted() -> in_shiny_server()
1 parent 5302f90 commit 5b2db2a

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

shiny/bookmark/_restore_state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from urllib.parse import parse_qs, parse_qsl
1010

1111
from ._bookmark_state import local_restore_dir
12-
from ._utils import from_json_str, is_hosted
1312
from ._types import BookmarkRestoreDirFn
13+
from ._utils import from_json_str, in_shiny_server
1414

1515
if TYPE_CHECKING:
1616
from .._app import App
@@ -191,7 +191,7 @@ async def _load_state_qs(self, query_string: str, *, app: App) -> None:
191191
load_bookmark_fn: BookmarkRestoreDirFn | None = app._bookmark_restore_dir_fn
192192

193193
if load_bookmark_fn is None:
194-
if is_hosted():
194+
if in_shiny_server():
195195
raise NotImplementedError(
196196
"The hosting environment does not support server-side bookmarking."
197197
)

shiny/bookmark/_save_state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from .._utils import private_random_id
99
from ..reactive import isolate
1010
from ._bookmark_state import local_save_dir
11-
from ._utils import is_hosted, to_json_str
1211
from ._types import BookmarkSaveDirFn
12+
from ._utils import in_shiny_server, to_json_str
1313

1414
if TYPE_CHECKING:
1515
from shiny._app import App
@@ -75,7 +75,7 @@ async def _save_state(self, *, app: App) -> str:
7575
save_bookmark_fn: BookmarkSaveDirFn | None = app._bookmark_save_dir_fn
7676

7777
if save_bookmark_fn is None:
78-
if is_hosted():
78+
if in_shiny_server():
7979
# TODO: Barret; Implement `bookmark_save_dir` for Connect
8080
raise NotImplementedError(
8181
"The hosting environment does not support server-side bookmarking."

shiny/bookmark/_utils.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66
import orjson
77

88

9-
def is_hosted() -> bool:
10-
# Can't look at SHINY_PORT, as we already set it in shiny/_main.py's `run_app()`
9+
# https://github.com/rstudio/shiny/blob/f55c26af4a0493b082d2967aca6d36b90795adf1/R/server.R#L510-L514
10+
def in_shiny_server() -> bool:
11+
shiny_port = os.environ.get("SHINY_PORT")
12+
if shiny_port is None or shiny_port == "":
13+
return False
1114

12-
# TODO: Barret: Q: How to support shinyapps.io? Or use `SHINY_PORT` how R-shiny did
13-
14-
# Instead, looking for the presence of the environment variable that Connect sets
15-
# (*_Connect) or Shiny Server sets (SHINY_APP)
16-
for env_var in ("POSIT_CONNECT", "RSTUDIO_CONNECT", "SHINY_APP"):
17-
if env_var in os.environ:
18-
return True
19-
return False
15+
return True
2016

2117

2218
def to_json_str(x: Any) -> str:

0 commit comments

Comments
 (0)