Configure your Shiny app to use polished.
Below is a simple polished Shiny app. If you replace "<your polished.tech secret API key>" with your polished.tech secret API key from step
4, you should be able to copy and paste the below code into a folder containing "global.R", "ui.R", and "server.R" files and run a polished Shiny app.
# global.R
library(shiny)
library(polished)
# configure the global sessions when the app initially starts up.
polished::global_sessions_config(
app_name = "my_first_shiny_app",
api_key = "<your polished.tech secret API key>"
)
# ui.R
ui <- fluidPage(
fluidRow(
column(
6,
h1("Hello Shiny!")
),
column(
6,
br(),
actionButton(
"sign_out",
"Sign Out",
icon = icon("sign-out-alt"),
class = "pull-right"
)
),
column(
12,
verbatimTextOutput("user_out")
)
)
)
polished::secure_ui(ui)
# server.R
server <- function(input, output, session) {
output$user_out <- renderPrint({
session$userData$user()
})
observeEvent(input$sign_out, {
sign_out_from_shiny()
session$reload()
})
}
polished::secure_server(server)
That's it! You now have a secured Shiny app complete with sign in and registration pages, email verification, and password reset among other features. Use the polished.tech dashboard to grant your email address access to your Shiny app, and you can register and sign in.
The above Shiny app should look like this:
Next Steps
Now that you have set up polished, let's go to the next page to customize your sign in and registration pages.