We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.
Checkout the full R-Shiny playlist here 👉 PLAYLIST
Code
Press to unfold code
library(shiny)library(bslib)library(shinyvalidate)ui <-page_fluid(div(class ='m-2',h1('Shiny Validation Demo'),div(class ='d-flex',textInput('in_txt_name', 'What is your name?'),div(class ='ms-2',selectizeInput('in_select_month','Select your desired month',choices = month.name,multiple =TRUE,#options = list(maxItems = 3) ) ) ),verbatimTextOutput('out_verbatim_txt') ))server <-function(input, output, session) { iv <- InputValidator$new() iv$add_rule("in_txt_name", sv_required()) iv$add_rule("in_select_month", sv_required()) iv$add_rule("in_txt_name", \(x) { is_long_enough_name <- stringr::str_length(x) >=3if (!is_long_enough_name) {"Please provide a name of length that is at least 3" } }) iv$add_rule("in_select_month", \(x) { is_only_three_months <-length(x) <=3if (!is_only_three_months) {"Please provide at most 3 months" } }) iv$enable() output$out_verbatim_txt <-renderPrint({ is_long_enough_name <- stringr::str_length(input$in_txt_name) >=3 is_at_least_one_month <-length(input$in_select_month) >=1 is_only_three_months <-length(input$in_select_month) <=3validate(need( is_long_enough_name,"Please provide a name of length that is at least 3" ),need(is_at_least_one_month, "Please provide a month"),need(is_only_three_months, "Please provide at most 3 months"), ) epoxy::epoxy("Hi {input$in_txt_name}, you selected {.and input$in_select_month}." ) })}shinyApp(ui, server) |>print()
This in-depth video course teaches you everything you need to know about becoming better & more efficient at cleaning up messy data. This includes Excel & JSON files, text data and working with times & dates. If you want to get better at data cleaning, check out the course page.
Insightful Data Visualizations for "Uncreative" R Users
This video course teaches you how to leverage {ggplot2} to make charts that communicate effectively without being a design expert. Course information can be found on the course page.