0

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? Commented Feb 3, 2020 at 19:51
  • groups would be more convenient but is that doable with shinyapps Commented Feb 3, 2020 at 21:10
  • I added an answer below. Did you find it useful? Commented Feb 10, 2020 at 20:08

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.