Form app template for R Shiny

A feedback form in R Shiny: text, choice and rating inputs, a conditional field, validation, a live table of responses and a CSV download. Free app.R.

The Feedback form template in the DropToApp editor: the app's layout with its inputs and outputs
The template in the DropToApp editor. Run it to see it working.

About this template

A form that collects feedback and shows the responses next to it. It covers what most form apps need: text fields, a drop-down, a rating, a comment box, a consent checkbox and a submit button.

Choosing “Other” as the topic reveals an extra field with a conditional panel. Submitting checks the name, adds a row to a table, clears the form and shows a notification. Responses can be downloaded as a CSV file. They are kept in memory, so connect a database or a Google Sheet when you need them to persist.

What's inside

  • A two-column layout on page_fillable()
  • A conditionalPanel() that shows a field only when it is needed
  • observeEvent() on the submit button, with simple validation and showNotification()
  • Responses stored in a reactiveVal() and shown in a table
  • A downloadButton() with downloadHandler() for a CSV export

The complete app.R

Download
# Generated by DropToApp
library(shiny)
library(bslib)

ui <- page_fillable(
  title = "Feedback form",
  layout_columns(
    col_widths = c(5, 7),
    card(
      card_header("Tell us what you think"),
      textInput("name", "Name"),
      textInput("email", "Email", placeholder = "[email protected]"),
      selectInput(
        "topic",
        "Topic",
        choices = c("Product", "Support", "Billing", "Other")
      ),
      conditionalPanel(
        "input.topic == 'Other'",
        textInput("topic_other", "Please specify")
      ),
      radioButtons(
        "rating",
        "How satisfied are you? (1 to 5)",
        choices = c("1", "2", "3", "4", "5"),
        selected = "4",
        inline = TRUE
      ),
      textAreaInput("comments", "Comments", rows = 4),
      checkboxInput("contact", "You may contact me about my feedback"),
      actionButton("submit", "Send feedback", class = "btn-primary")
    ),
    card(
      card_header("Responses"),
      tableOutput("responses"),
      downloadButton("download", "Download as CSV")
    )
  )
)

server <- function(input, output, session) {
  # Inputs: input$name, input$email, input$topic, input$topic_other, input$rating, input$comments, input$contact

  # Responses are kept in memory while the app runs
  responses <- reactiveVal(data.frame(
    time = character(), name = character(), email = character(), topic = character(),
    rating = integer(), comments = character(), contact = logical()
  ))

  observeEvent(input$submit, {
    if (!nzchar(trimws(input$name))) {
      showNotification("Please enter your name.", type = "warning")
    } else {
      topic <- if (input$topic == "Other") input$topic_other else input$topic
      row <- data.frame(
        time = format(Sys.time(), "%Y-%m-%d %H:%M"), name = input$name, email = input$email,
        topic = topic, rating = as.integer(input$rating), comments = input$comments,
        contact = input$contact
      )
      responses(rbind(responses(), row))
      updateTextInput(session, "name", value = "")
      updateTextInput(session, "email", value = "")
      updateTextAreaInput(session, "comments", value = "")
      showNotification("Thank you for your feedback!", type = "message")
    }
  })

  output$responses <- renderTable({
    responses()
  })

  output$download <- downloadHandler(
    filename = "responses.csv",
    content = function(file) {
      write.csv(responses(), file, row.names = FALSE)
    }
  )
}

shinyApp(ui, server)

How to run it

  1. In your browser: run it with shinylive. R runs on your computer with webR; the first start downloads R and the packages, which can take a minute.
  2. In R or RStudio: save the code as app.R, install the packages once with install.packages(c("shiny", "bslib")), then run shiny::runApp() in the folder with the file.
  3. In DropToApp: open the template in the editor to change the layout by drag and drop or edit the code, and export your own app.R.

More Shiny templates

Screenshot of the KPI dashboard Shiny template in the DropToApp editor

KPI dashboard

A Shiny dashboard with KPI value boxes, sidebar filters, a chart and a top-5 table, built with bslib on R’s airquality data. Free app.R to copy, edit and run.

DashboardValue boxesFilters
Screenshot of the Data explorer Shiny template in the DropToApp editor

Data explorer

Pick a dataset and two columns to get a scatter plot, a searchable DT table and a summary, with axis choices that update per dataset. Free R Shiny template.

Data explorationDT tableTabs
Screenshot of the Multi-page app Shiny template in the DropToApp editor

Multi-page app

A Shiny app with several pages in a navigation bar: an overview with value boxes and an accordion, an interactive plotly chart and a DT data table.

Multi-pagePlotlyAccordion
Screenshot of the CSV upload and explorer Shiny template in the DropToApp editor

CSV upload and explorer

Upload a CSV file, choose the separator, and see its rows, columns, a searchable table and a summary. Download the data again as CSV. Free Shiny app template.

File uploadDT tableDownload
Screenshot of the Histogram explorer Shiny template in the DropToApp editor

Histogram explorer

The classic first Shiny app, rebuilt with bslib: a slider and a variable picker drive a histogram of the Old Faithful geyser data. Free app.R to copy and run.

BeginnerCharts