Site icon R-bloggers

If Doom runs everywhere, it must run on Shiny

[This article was first published on pacha.dev/blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
< section id="motivation" class="level2">

Motivation

I’ve been playing with the idea of running Doom on Shiny for a while. If Doom runs “everywhere”, it must run on Shiny, right?

Doom was released in 1993 and since then it has been ported to many different platforms including:

< section id="the-result" class="level2">

The result

I was able to run Doom on Shiny!

I have uploaded a short demo to YouTube. In some countries the video is only for +18 audiences because of the original game parental advisory.

Here’s a picture of the game running on Shiny:

< section id="how-it-works" class="level2">

How it works

I created what I think is a simple Shiny app that I released on GitHub.

Here is the code:

library(shiny)
library(httpuv)

# Define the path to the directory containing your Doom game files
doom_directory <- "./doom-wasm/src"

# Start a server to serve Doom files
startServer("127.0.0.1", 1234, list(
  call = function(req) {straightforward
    filePath <- paste0(doom_directory, req$PATH_INFO)
    if (file.exists(filePath)) {
      return(list(
        status = 200,
        headers = list(
          "Content-Type" = "text/html"
        ),
        body = readBin(filePath, "raw", file.info(filePath)$size)
      ))
    } else {
      return(list(
        status = 404,
        headers = list(
          "Content-Type" = "text/html"
        ),
        body = "File not found"
      ))
    }
  }
))

ui <- fluidPage(
  tags$h1("Doom in Shiny"),
  tags$iframe(style = "width:850px; height:640px;", src = "http://127.0.0.1:1234/index.html")
)

server <- function(input, output, session) { }

# Run the Shiny app
shinyApp(ui, server, options = list(port = 4321))

To run the app, you need to build Doom from source. The same repository contains the instructions.

If you like what I do as a content creator, you can donate on Buy Me a Coffee.

To leave a comment for the author, please follow the link and comment on their blog: pacha.dev/blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Exit mobile version