I have the shiny app below in which there are 2 users the shiny(admin) and the shinymanager. Depending on which credentials the user may use he sees a different selectInput() "Variable".
What I want to do is to give the shiny user the ability to set the values that the shinymanager will see in his "Variable" selectInput() with the "Choices" selectInput().
# define some credentials
credentials <- data.frame(
user = c("shiny", "shinymanager"), # mandatory
password = c("azerty", "12345"), # mandatory
start = c("2019-04-15"), # optinal (all others)
expire = c(NA, NA),
admin = c(FALSE, TRUE),
comment = "Simple and secure authentification mechanism
for single ‘Shiny’ applications.",
stringsAsFactors = FALSE
)
library(shiny)
library(shinymanager)
ui <- fluidPage(
tags$h2("My secure application"),
uiOutput("myinput"),
uiOutput("chs"),
actionButton("action_logout", "Logout")
)
# Wrap your UI with secure_app
ui <- secure_app(ui)
server <- function(input, output, session) {
observeEvent(input$action_logout, {
session$reload()
})
# call the server part
# check_credentials returns a function to authenticate users
res_auth <- secure_server(
check_credentials = check_credentials(credentials)
)
output$chs<-renderUI({
if (reactiveValuesToList(res_auth)$user == "shiny") {
selectInput("ch",
"Choices:",
choices = c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear"),selected="cyl,multiple = T)
}
else{
}
})
output$myinput <- renderUI({
if (reactiveValuesToList(res_auth)$user == "shiny") {
# if (TRUE) {
mychoices <- c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear")
} else {
mychoices <- input$ch
}
selectInput("variable",
"Variable:",
choices = mychoices)
})
}
shinyApp(ui, server)
We somehow need to save the choices made by the
shinyuser, but you would need to think about, to which point in time the choices should be saved. In the example below I just save the choices each time theinput$choicesare changed. I just usesaveRDSandreadRDSto save it in the working directory of the app, but you can use a subfolder or a database or whatever other options you might have.You would also need to think about, what the
shinymanagersee if no choices have been saved so far - I left this out in the approach below.