-
Notifications
You must be signed in to change notification settings - Fork 83
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
[bug]: starlette request object does not have the query parameters in shinylive #1794
Comments
Hi @JoseBlanca, thanks for your question. Unfortunately, query parameters in shinylive aren't as easily handled as they are for normal Shiny apps. The technical reason for this is that shinylive apps are run inside We've discussed this in posit-dev/r-shinylive#28 and have done some exploratory work in this direction in posit-dev/shinylive#79. If you only have a single app on your page, another Shiny user has shared this JavaScript snippet that you could use to reflect the parent page hash to the Shiny app (you'd need to update it to reflect query parameters too). $(function() {
$(window.parent).on('hashchange', function (e) {
$('#currentHash').val(window.parent.location.hash).change();
});
}); |
Now I get it. Thanks. This behavior has been quite surprising to me because it worked during the development in Visual Studio Code and it failed when I tried to deploy the application. The application is supposed to changed the UI according to the url query params, but that's not working, now I understand why. Thanks for the javascript tip, but I don't think I will be able to fix it. I don't know enough JavaScript, that's one of my motivations for using shiny and not just pyscript. Moreover, given my limited knowledge of both javascript and the shinylive internals, I don't know how reliable and stable that fix would be and I don't know if it would stable enough to use it in production. Jose Blanca |
A friend has help me out, and she has created a workaround that seems to work.
|
I want to access the query parameters to configure my app UI and behavior according to them.
To get the query parameters I have followed the method given in this comment.
A test App.
While I was developing my App inside Visual Studio Code I was getting the correct result:
URL: http://localhost:32997/?param=hi
Html ouput:
Serving the App with uvicorn also works as expected.
Shell command:$ uv run uvicorn app:app
URL: http://127.0.0.1:8000/?param=hi
Html ouput:
However, when I try to use shiny live, and that was my original intention, I loose the query parameters.
Shell command:$ rm -r tmp_shiny_site; uv run shinylive export src/apps/request_test_app/ tmp_shiny_site/; uv run python -m http.server --directory tmp_shiny_site --bind localhost 8008
URL: http://[::1]:8008/?param=hi
Html ouput:
Best,
Jose Blanca
The text was updated successfully, but these errors were encountered: