Skip to content

Instantly share code, notes, and snippets.

@rpodcast
Created February 2, 2017 05:04
Show Gist options
  • Save rpodcast/4220ab11df71d034eb88d293f311fdef to your computer and use it in GitHub Desktop.
Save rpodcast/4220ab11df71d034eb88d293f311fdef to your computer and use it in GitHub Desktop.
Using rintrojs with a navbar UI
library(shiny)
library(rintrojs)
data(mtcars)
my_data <- mtcars
# Define server logic required to draw a histogram
shinyServer(function(input, output, session) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
output$summary <- renderPrint({
summary(my_data[[input$var]])
})
observeEvent(input$btn, {
introjs(session)
})
})
# Define UI for application that draws a histogram
shinyUI(fluidPage(
introjsUI(),
navbarPage("navbar",
tabPanel(
"Plot",
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
introBox(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
data.step = 1,
data.intro = "Use this slider to select number of bins"
),
actionButton("btn", "Click me")
),
# Show a plot of the generated distribution
mainPanel(
introBox(
plotOutput("distPlot"),
data.step = 2,
data.intro = "This is the histogram"
)
)
)
),
tabPanel(
"Summaries",
sidebarLayout(
sidebarPanel(
introBox(
selectInput("var",
"Variable",
c("mpg", "drat", "wt"),
selected = "mpg"
),
data.step = 3,
data.intro = "Select the variable you want summarized"
)
),
mainPanel(
verbatimTextOutput("summary")
)
)
)
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment