Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken code in chapter 5 #146

Open
DivadNojnarg opened this issue Jan 5, 2024 · 0 comments
Open

Broken code in chapter 5 #146

DivadNojnarg opened this issue Jan 5, 2024 · 0 comments

Comments

@DivadNojnarg
Copy link
Owner

With new Shiny, httpuv and cie...: this code does not work because the dependencies folder structure has changed (jQuery is also updated). Now folders are prefixed by the dependency version and this code does not account for it, leading to wrong file path in the HTML template. Thanks @hypebright for checking. The underlying concept/big picture remains unchanged.

library(shiny)
library(htmltools)
library(httpuv)

ui <- fluidPage(
  titlePanel("Old Faithful Geyser Data"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),
    mainPanel(
      plotOutput("distPlot")
    )
  )
)

ui <- htmlTemplate(
  system.file("template", "default.html", package = "shiny"), 
  lang = "en", 
  body = tags$body(ui), 
  document_ = TRUE
)

html <- renderDocument(
  ui,
  deps = c(
    list(
      htmlDependency(
        "jquery", 
        "3.5.1", 
        c(href = "shared"), 
        script = "jquery.min.js"
      )
    ), 
    shiny:::shinyDependencies() # Shiny JS + CSS
  ),
  processDep = createWebDependency
)

app <- list()
app$call <- function(req) {
  list(
    status = 200L,
    headers = list(
      'Content-Type' = 'text/html'
    ),
    body = html
  )
}

app$staticPaths <- list(shared = system.file(
  package = "shiny", 
  "www", 
  "shared"
))

s <- startServer(
  "127.0.0.1",
  8080,
  app
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant