Basic Shiny application for use on Sage Bionetworks' Synapse web portal.
- Maintainer: thomasyu888
- Contributors: allaway, duncan-palmer, jkiang13, karawoo, kdaily, vpchung
Shiny applications are a powerful way to develop interactive data visualization and manipulation interfaces. However, when using with Synapse, user authentication is an issue - whomever the Shiny application is running as will determine the access that users visiting the application will have.
This solution allows to determine which user is currently logged into Synapse through the web browser. These credentials are passed on to the Shiny app, and that specific user is logged in. Subsequent interactions with Synapse to pull data for the Shiny interface then happens as that user.
-
Ensure that each user gets a separate R process by customizing the utilization scheduler (only available for Shiny Server Pro).
-
Write your app so that it logs in before doing any operation that interacts with Synapse. Essentially this means writing wrappers for every synapser function you use, e.g.:
authSynGet <- function(...) { synLogin(sessionToken = input$cookie) synGet(...) }
Placing a call to
synLogin()
beforesynGet()
directly in your server function is not necessarily sufficient, as it is still possible someone else could log in between when yoursynLogin()
andsynGet()
are executed. -
Instead of using synapser, use the Synapse Python client + reticulate. The Python client allows for creating multiple client objects, and therefore multiple authenticated users. Please see the reticulate branch for implementation details.
⚠️ It is important to avoid using the synapseclient.login() command without arguments, in other words, explicitly pass authToken to this function. Otherwise you will risk logging in as a user specified in .synapseConfig or .synapseSession instead of the app user.
To create a new Shiny application based on this structure, do not fork this repository directly on GitHub. Instead, please use GitHub's importer following the instructions below.
- Go to GitHub's importer and paste in this repository's clone URL (https://github.com/Sage-Bionetworks/SynapseShinyApp.git).
- Choose a name for your repository.
- Select the owner for your repository (This will probably be you, but may instead be an organization you belong to).
You can now click "Begin Import". When the process is done, you can click "Continue to repository" to visit your newly-created repository.
If you are using a navbarPage
instead of a fluidPage
in your ui.R
, use of this code:
tags$head(
singleton(
includeScript("www/readCookie.js")
)
),
will cause create a default ghost tab. Instead, you should replace the above code with this snippet:
header=list(tags$head(includeScript("www/readCookie.js"))),