I am trying to build a shiny app where the user view changes based on who has logged in. I have seen examples of this being done using Shiny server pro or R Studio connect but since we don't have much budget for that software we are still doing it using shinyapps io. Has any tried doing it there or have some examples which I can refer to . Thank you.
3
-
Do you want every user to have a personalized view, or do you have some kind of user groups?annhak– annhak2020-02-03 19:51:17 +00:00Commented Feb 3, 2020 at 19:51
-
groups would be more convenient but is that doable with shinyappsSNT– SNT2020-02-03 21:10:07 +00:00Commented Feb 3, 2020 at 21:10
-
I added an answer below. Did you find it useful?annhak– annhak2020-02-10 20:08:25 +00:00Commented Feb 10, 2020 at 20:08
Add a comment
|
1 Answer
You can ask the user to log in in the shiny app, and use conditionalPanel logic to render different UIs for different groups.
The minimal reproducible example:
library(shiny)
ui <- fluidPage(
conditionalPanel(
condition = "output.group == 0",
textInput("groupname", "Enter your group name to proceed")
),
conditionalPanel(
condition = "output.group == 1",
uiOutput("group1UI")
),
conditionalPanel(
condition = "output.group == 2",
uiOutput("group2UI")
)
)
server <- function(input, output) {
# Logic for deciding the group
output$group <- reactive({
if (input$groupname == "group1") {
return(1)
} else if (input$groupname == "group2") {
return(2)
} else {
return(0)
}
})
outputOptions(output, "group", suspendWhenHidden = FALSE)
# View for group 1
output$group1UI <- renderUI({
mainPanel(
h3("Group 1 view"),
)
})
# View for group 2
output$group2UI <- renderUI({
mainPanel(
h3("Group 2 view"),
)
})
}
shinyApp(ui = ui, server = server)
Notice that this is not a secure way to identify the users / protect their data, just a way to build the functionality you desired. Security must be implemented separately, but it's beyond the scope here.