Skip to contents

This vignette will walk you through how to deploy your quiz created with shinyquiz to shinyapps.io. We’ll start by creating a simple quiz, and then we’ll go through the steps to deploy it online.

Creating a Quiz

First, let’s create a quiz using shinyquiz. Here’s an example:

library(shiny)
library(shinyquiz)

# Create the quiz
quiz <- shinyquiz::create_quiz(
  # ... (your example code here)
)

Previewing the Quiz Locally

Before deploying, you might want to preview your quiz to make sure it looks and functions as expected.


Building the Shiny App

Now that we have our quiz, let’s build the Shiny app that will host it. Here’s how you can do it:

# Build the shiny UI
ui <- shiny::fluidPage(
  htmltools::div(
    style = "max-width: 700px",
    shinyquiz::quiz_ui(quiz)
  )
)

# Build the server
server <- function(input, output, session) {
  shinyquiz::quiz_server(quiz)
}

# Run the app
shiny::shinyApp(ui, server)


Deploying to shinyapps.io

There’s two easy ways to deploy straight to shinyapps.io via Rstudio. For both, you’ll need to save your above code to a file app.R script. From there, you can either deploy it using the Rstudio interface via the blue button or using the rsconnect package. You can find up-to-date information regarding those methods on the Posit site.



Full Script

Here is a full, example version of the app.R file:

library(shiny)
library(shinyquiz)

# create the quiz 
quiz <- create_quiz(
  create_question(
    'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id ornare augue, fringilla molestie metus. Donec eget tortor tincidunt, sagittis dui volutpat, finibus est. Select nulla.',
    add_choice('Nulla vel'),
    add_choice('auctor nulla'),
    add_choice('nulla', correct = TRUE)
  ),
  create_question(
    'Molestie metus. Maecenas tincidunt maximus viverra. Sed non gravida quam. Phasellus at iaculis leo. Mauris congue aliquet dui, ut dapibus lorem porttitor sed.',
    add_choice('ATT'),
    add_choice('ATE', correct = TRUE),
    add_choice('ATC', correct = TRUE),
    label = 'Select ATE and ATC'
  ),
  create_question(
    'Sed non gravida quam. Phasellus at iaculis leo.',
    add_slider(10, 50, 30, correct = 20),
    label = 'Select 20'
  )
)

# build the shiny UI
ui <- shiny::fluidPage(
  htmltools::div(
    style = "max-width: 700px",
    quiz_ui(quiz)
  )
)

# build the server
server <- function(input, output, session) {
  quiz_server(quiz)
}

# run the app
shiny::shinyApp(ui, server)