rmd_file <- “presentation.Rmd” html_file <- “presentation.html” # will be overwritten by render
rmd_contents <- c( “—”, “title: "MPG Predictor — Pitch"”, “author:
"ATHANG DHARASKAR"”, “output:”, ” ioslides_presentation:“,” widescreen:
true”, “—”, ““,”# MPG Predictor”, ““,”A quick pitch for the Shiny
application.”, ““,”—“,”“,”# Problem & Audience”, ““,”- Problem:
People want a quick, intuitive estimate of a car’s fuel efficiency given
horsepower and weight.”, “- Audience: Intro stats students, car
enthusiasts, instructors demonstrating reactive apps.”, ““,”—“,”“,”# App
Features”, ““,”- Numeric inputs for horsepower and weight.”, “- Choice
of baseline or refit model.”, “- Prediction with 95% prediction
interval.”, “- Downloadable CSV and informative plot.”, ““,”—“,”“,”#
Live demo (embedded R
code)“,”“,”{r echo=TRUE, results='asis'}", "data(mtcars)", "model_demo <- lm(mpg ~ hp + wt, data = mtcars)", "newd <- data.frame(hp = 110, wt = 2.8)", "pred <- predict(model_demo, newd, interval = \"prediction\")", "cat(\"Example: hp=110, wt=2.8 -> predicted mpg =\", round(pred[,\"fit\"],3),", " \" (95% PI:\", round(pred[,\"lwr\"],3), \",\", round(pred[,\"upr\"],3), \")\")", "“,”“,”—“,”“,”#
How to access & publish”, ““,”- Files (ui.R,
server.R, presentation.Rmd) are ready to push
to GitHub.”, “- Publish this .Rmd to RPubs via the RStudio
Publish button or via the script (this will upload the
generated HTML).”, “” )
writeLines(rmd_contents, con = rmd_file) message(“Wrote R Markdown to:”, normalizePath(rmd_file))
required <- c(“rmarkdown”, “rsconnect”, “knitr”) to_install <- setdiff(required, rownames(installed.packages())) if (length(to_install)) { message(“Installing required packages:”, paste(to_install, collapse = “,”)) install.packages(to_install, repos = “https://cloud.r-project.org”) }
library(rmarkdown) library(rsconnect)
message(“Rendering”, rmd_file, ” to ioslides HTML…“) render_result <- tryCatch({ rmarkdown::render(rmd_file, output_file = html_file, quiet = TRUE) }, error = function(e) { stop(”Error rendering Rmd: “, conditionMessage(e)) })
message(“Rendered HTML:”, normalizePath(html_file))
default_title <- paste(“MPG Predictor Pitch -”, Sys.Date()) if (interactive()) { title_input <- readline(prompt = sprintf(“RPubs post title (press Enter for default: ‘%s’):”, default_title)) if (!nzchar(trimws(title_input))) title_input <- default_title } else { title_input <- default_title }
. message(“Uploading to RPubs…”) upload_result <- tryCatch({ # rsconnect::rpubsUpload(title, contentFile, originalDoc) rsconnect::rpubsUpload(title = title_input, contentFile = normalizePath(html_file), originalDoc = normalizePath(rmd_file)) }, error = function(e) { message(“Error during rpubsUpload():”, conditionMessage(e)) NULL })
if (is.null(upload_result)) { message(“RPubs upload failed. If you see a message about api.rpubs.com connectivity, check your internet/firewall or try the RStudio Publish button (Viewer -> Publish).”) } else { message(“Upload result:”) print(upload_result) # continueUrl is usually where you finish publishing in the browser if (!is.null(upload_result\(continueUrl)) { message("Open this URL in your browser to complete/publish and copy the final RPubs link:") message(upload_result\)continueUrl) } else if (!is.null(upload_result\(url)) { message("Published! Your RPubs URL is: ", upload_result\)url) } else { message(“RPubs returned upload info. If the publish did not open automatically, check your RPubs account.”) } }
message(“Done. If you prefer the GUI: open the generated HTML in Viewer and click Publish -> RPubs.”) ########################################################################