|
| 1 | +flight_schema <- function(language = "en") { |
| 2 | + list( |
| 3 | + title = if(language=="en") "✈️ Flight Booking" else "✈️ Flugbuchung", |
| 4 | + description = if(language=="en") |
| 5 | + "Book your next trip in a few simple steps." else |
| 6 | + "Buchen Sie Ihre nächste Reise in wenigen Schritten.", |
| 7 | + locale = language, |
| 8 | + showProgressBar = "top", |
| 9 | + pages = list( |
| 10 | + list( |
| 11 | + name = "route", |
| 12 | + elements = list( |
| 13 | + list(type="text", name="from", title=if(language=="en") "From" else "Von", isRequired=TRUE, placeHolder="City or Airport"), |
| 14 | + list(type="text", name="to", title=if(language=="en") "To" else "Nach", isRequired=TRUE, placeHolder="City or Airport"), |
| 15 | + list(type="text", name="depart", title=if(language=="en") "Departure Date" else "Abflugdatum", inputType="date", isRequired=TRUE), |
| 16 | + list(type="text", name="return", title=if(language=="en") "Return Date (optional)" else "Rückflugdatum (optional)", inputType="date") |
| 17 | + ) |
| 18 | + ), |
| 19 | + list( |
| 20 | + name = "passengers", |
| 21 | + elements = list( |
| 22 | + list(type="dropdown", name="adults", title=if(language=="en") "Adults" else "Erwachsene", choices=as.character(1:6), defaultValue="1"), |
| 23 | + list(type="dropdown", name="children", title=if(language=="en") "Children" else "Kinder", choices=as.character(0:4), defaultValue="0"), |
| 24 | + list(type="dropdown", name="class", title=if(language=="en") "Class" else "Klasse", |
| 25 | + choices=if(language=="en") c("Economy", "Premium Economy", "Business", "First") else c("Economy", "Premium Economy", "Business", "First"), isRequired=TRUE) |
| 26 | + ) |
| 27 | + ), |
| 28 | + list( |
| 29 | + name = "addons", |
| 30 | + elements = list( |
| 31 | + list(type="checkbox", name="addons", title=if(language=="en") "Add-ons" else "Zusatzleistungen", |
| 32 | + choices=if(language=="en") |
| 33 | + c("Checked Bag (+$40)", "Seat Selection (+$10)", "Extra Legroom (+$20)", "Priority Boarding (+$15)") |
| 34 | + else |
| 35 | + c("Aufgabegepäck (+40€)", "Sitzplatzwahl (+10€)", "Mehr Beinfreiheit (+20€)", "Priority Boarding (+15€)") |
| 36 | + ), |
| 37 | + list(type="text", name="requests", title=if(language=="en") "Special Requests" else "Besondere Wünsche", inputType="textarea", placeHolder=if(language=="en") "e.g. Vegetarian meal" else "z.B. vegetarisches Essen") |
| 38 | + ) |
| 39 | + ), |
| 40 | + list( |
| 41 | + name = "contact", |
| 42 | + elements = list( |
| 43 | + list(type="text", name="name", title=if(language=="en") "Your Name" else "Ihr Name", isRequired=TRUE), |
| 44 | + list(type="text", name="email", title=if(language=="en") "Email Address" else "E-Mail-Adresse", inputType="email", isRequired=TRUE), |
| 45 | + list(type="text", name="phone", title=if(language=="en") "Phone Number" else "Telefonnummer", inputType="tel") |
| 46 | + ) |
| 47 | + ), |
| 48 | + list( |
| 49 | + name = "summary", |
| 50 | + elements = list( |
| 51 | + list( |
| 52 | + type="expression", name="summary", |
| 53 | + title=if(language=="en") "<h4>Booking Summary</h4>" else "<h4>Buchungsübersicht</h4>", |
| 54 | + expression=paste0( |
| 55 | + "'<b>Route:</b> ' + from + ' → ' + to + '<br>' + ", |
| 56 | + "'<b>Departure:</b> ' + depart + (return ? ', <b>Return:</b> ' + return : '') + '<br>' + ", |
| 57 | + "'<b>Adults:</b> ' + adults + ', <b>Children:</b> ' + children + '<br>' + ", |
| 58 | + "'<b>Class:</b> ' + class + '<br>' + ", |
| 59 | + " (addons ? '<b>Add-ons:</b> ' + join(addons, ', ') + '<br>' : '') + ", |
| 60 | + " (requests ? '<b>Requests:</b> ' + requests + '<br>' : '') + ", |
| 61 | + "'<b>Name:</b> ' + name + '<br>' + ", |
| 62 | + "'<b>Email:</b> ' + email" |
| 63 | + ) |
| 64 | + ), |
| 65 | + list( |
| 66 | + type = "html", |
| 67 | + html = if(language=="en") |
| 68 | + "<span style='color:#666'>Review your booking and click <b>Complete</b> to finish.</span>" |
| 69 | + else |
| 70 | + "<span style='color:#666'>Überprüfen Sie Ihre Buchung und klicken Sie auf <b>Abschließen</b>.</span>" |
| 71 | + ) |
| 72 | + ) |
| 73 | + ) |
| 74 | + ), |
| 75 | + completedHtml = if(language=="en") |
| 76 | + "<h3>Thank you for booking your flight!<br>We wish you a pleasant journey. ✈️</h3> |
| 77 | + <div style='color:#555'>A confirmation will be sent to your email address.</div>" |
| 78 | + else |
| 79 | + "<h3>Vielen Dank für Ihre Flugbuchung!<br>Wir wünschen Ihnen eine gute Reise. ✈️</h3> |
| 80 | + <div style='color:#555'>Eine Bestätigung wird an Ihre E-Mail-Adresse gesendet.</div>" |
| 81 | + ) |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | +library(shiny) |
| 86 | +library(rsurveyjs) |
| 87 | + |
| 88 | +ui <- fluidPage( |
| 89 | + tags$head( |
| 90 | + # Sky CSS background, some clouds and fade |
| 91 | + tags$style(HTML(" |
| 92 | + body { |
| 93 | + background: linear-gradient(to bottom,#93c9ff 0%,#cce6ff 80%,#fff 100%); |
| 94 | + min-height:100vh; |
| 95 | + } |
| 96 | + .sky-bg { |
| 97 | + position: fixed; |
| 98 | + top:0; left:0; width:100vw; height:100vh; |
| 99 | + z-index:-1; |
| 100 | + overflow:hidden; |
| 101 | + } |
| 102 | + .cloud { |
| 103 | + position: absolute; |
| 104 | + background: #fff; |
| 105 | + border-radius: 50%; |
| 106 | + opacity: 0.60; |
| 107 | + } |
| 108 | + .cloud1 { width: 110px; height: 60px; top: 70px; left: 14vw;} |
| 109 | + .cloud2 { width: 70px; height: 35px; top: 160px; left: 60vw;} |
| 110 | + .cloud3 { width: 150px; height: 60px; top: 240px; left: 38vw; opacity:0.45;} |
| 111 | + .cloud4 { width: 80px; height: 40px; top: 330px; left: 70vw; opacity:0.3;} |
| 112 | + .form-container { |
| 113 | + max-width: 600px; |
| 114 | + margin: 60px auto 24px auto; |
| 115 | + background: #fff; |
| 116 | + border-radius: 18px; |
| 117 | + box-shadow: 0 6px 32px #85b8ff33; |
| 118 | + padding: 36px 28px 18px 28px; |
| 119 | + } |
| 120 | + h2 { text-align: center; color: #2177d2; margin-bottom:0.4em;} |
| 121 | + .sv_p_root { background: #f7fcff !important;} |
| 122 | + .sv-question__title { color: #2177d2 !important;} |
| 123 | + .sv-body__footer { text-align:center;} |
| 124 | + ")) |
| 125 | + ), |
| 126 | + # Animated clouds (simple, can be extended with JS if wanted) |
| 127 | + div(class="sky-bg", |
| 128 | + div(class="cloud cloud1"), |
| 129 | + div(class="cloud cloud2"), |
| 130 | + div(class="cloud cloud3"), |
| 131 | + div(class="cloud cloud4") |
| 132 | + ), |
| 133 | + div(class="form-container", |
| 134 | + h2("✈️ Flight Booking"), |
| 135 | + selectInput("lang", "🌐 Language / Sprache", choices = c("English" = "en", "Deutsch" = "de"), width = "220px"), |
| 136 | + surveyjsOutput("flight_form"), |
| 137 | + br(), h4("📝 Live Preview"), verbatimTextOutput("flight_data", placeholder = TRUE) |
| 138 | + ) |
| 139 | +) |
| 140 | + |
| 141 | +server <- function(input, output, session) { |
| 142 | + output$flight_form <- renderSurveyjs({ |
| 143 | + surveyjs( |
| 144 | + schema = flight_schema(input$lang), |
| 145 | + theme = "Modern", |
| 146 | + live = TRUE, |
| 147 | + theme_vars = list( |
| 148 | + "--sjs-primary-backcolor" = "#2177d2", |
| 149 | + "--sjs-questionpanel-backcolor" = "#f7fcff" |
| 150 | + ) |
| 151 | + ) |
| 152 | + }) |
| 153 | + output$flight_data <- renderPrint({ |
| 154 | + input$flight_form_data_live |
| 155 | + }) |
| 156 | +} |
| 157 | + |
| 158 | +shinyApp(ui, server) |
0 commit comments