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

Pass URL query parameters to the Shiny app in Viewer.tsx #79

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Components/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function setupAppProxyPath(proxy: PyodideProxy | WebRProxy): {
function createHttpRequestChannel(
proxy: PyodideProxy | WebRProxy,
appName: string,
urlPath: string
urlPath: string,
): MessageChannel {
if (!navigator.serviceWorker.controller) {
throw new Error("ServiceWorker controller was not found!");
Expand All @@ -79,7 +79,7 @@ function createHttpRequestChannel(
type: "configureProxyPath",
path: urlPath,
},
[httpRequestChannel.port2]
[httpRequestChannel.port2],
);

return httpRequestChannel;
Expand All @@ -88,15 +88,15 @@ function createHttpRequestChannel(
async function resetPyAppFrame(
pyodide: PyodideProxy,
appName: string,
appFrame: HTMLIFrameElement
appFrame: HTMLIFrameElement,
): Promise<void> {
// Reset the app iframe before shutting down the app, so that the user doesn't
// see the flash of gray indicating a closed session.
appFrame.src = "";

const stoppedPreviousApp = (await pyodide.runPyAsync(
`_stop_app('${appName}')`,
{ returnResult: "value", printResult: false }
{ returnResult: "value", printResult: false },
)) as boolean;

// If we stopped a previously-running app, pause for a bit before continuing.
Expand All @@ -108,7 +108,7 @@ async function resetPyAppFrame(
async function resetRAppFrame(
webRProxy: WebRProxy,
appName: string,
appFrame: HTMLIFrameElement
appFrame: HTMLIFrameElement,
): Promise<void> {
// Reset the app iframe before shutting down the app, so that the user doesn't
// see the flash of gray indicating a closed session.
Expand Down Expand Up @@ -136,7 +136,7 @@ export function Viewer({
>("loading");
const shinyIntervalRef = React.useRef<number>(0);
const [lastErrorMessage, setLastErrorMessage] = React.useState<string | null>(
null
null,
);

// Shiny for R
Expand Down Expand Up @@ -171,8 +171,8 @@ export function Viewer({
Object.fromEntries(
appCode.map((file) => {
return [file.name, file.content];
})
)
}),
),
);
try {
await webRProxy.runRAsync(".save_files(files, appDir)", {
Expand All @@ -195,7 +195,7 @@ export function Viewer({
webRProxy.runRAsync(".shiny_tick()");
}, 100);

viewerFrameRef.current.src = appInfo.urlPath;
viewerFrameRef.current.src = appInfo.urlPath + window.location.search;
setAppRunningState("running");
} catch (e) {
setAppRunningState("errored");
Expand Down Expand Up @@ -264,7 +264,7 @@ export function Viewer({
args: [appName],
});

viewerFrameRef.current.src = appInfo.urlPath;
viewerFrameRef.current.src = appInfo.urlPath + window.location.search;
setAppRunningState("running");
} catch (e) {
setAppRunningState("errored");
Expand All @@ -283,7 +283,7 @@ export function Viewer({
await resetPyAppFrame(
pyodideproxy,
appInfo.appName,
viewerFrameRef.current
viewerFrameRef.current,
);
setAppRunningState("empty");
}
Expand Down