Last active
July 31, 2020 10:47
-
-
Save mine-cetinkaya-rundel/d0a5e563eaff8ffdbfb271fddfe5c8ba to your computer and use it in GitHub Desktop.
Intro walkthrough in Shiny app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(rintrojs) | |
ui <- fluidPage( | |
introjsUI(), # Must include UI | |
titlePanel("Hello Shiny!"), | |
sidebarLayout( | |
sidebarPanel( | |
sliderInput(inputId = "bins", | |
label = "Number of bins:", | |
min = 1, | |
max = 50, | |
value = 30) | |
), | |
mainPanel( | |
introBox( | |
actionButton("btn","CLICK ME FIRST"), # Button to start the intro | |
data.step = 1, # This needs to be clicked first | |
data.intro = "This is the button" | |
), | |
introBox( # Highlight around the plot | |
plotOutput("distPlot"), | |
data.step = 2, # This comes second | |
data.intro = "This is the plot" | |
) | |
) | |
) | |
) | |
server <- function(input, output, session) { # Need session | |
output$distPlot <- renderPlot({ | |
x <- faithful$waiting | |
bins <- seq(min(x), max(x), length.out = input$bins + 1) | |
hist(x, breaks = bins, col = "#75AADB", border = "white", | |
xlab = "Waiting time to next eruption (in mins)", | |
main = "Histogram of waiting times") | |
}) | |
observeEvent( | |
input$btn, # Like any other action button | |
introjs(session) # Initiates an introduction via the intro.js library | |
) | |
} | |
# Create Shiny app ---- | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment