ambiorix-web / ambiorix

🖥️ Web framework for R
http://ambiorix.dev
GNU General Public License v3.0
211 stars 9 forks source link

Trying to run a post example #37

Closed Stephen-McDaniel closed 3 years ago

Stephen-McDaniel commented 3 years ago

Two changes needed to make this work with the master version.

1) I updated your post example at https://ambiorix.john-coene.com/#/examples/post should be to:

# app.R

library(ambiorix)
library(htmltools)
library(mime)

app <- Ambiorix$new()

app$get("/", function(req, res){

   # form
   # sends to /submit
  form <- tagList(
    tags$form(
      action = "/submit", enctype = "multipart/form-data", method = "POST",
      p(
        tags$label('for' = "first_name", "First Name"),
        tags$input(type = "text", name = "first_name")
      ),
      tags$input(type = "submit")
    )
  )

  res$send(form)
})

app$post("/submit", function(req, res){
  body <- parse_multipart(req$body)
  res$send(h1("Your name is", body$first_name))
})

app$start()

2) And modified the master Dockerfile include the mime package install after htmltools:

RUN R -e "install.packages('mime')"

Then the post example works with my docker test server.

Nice work! Stephen

JohnCoene commented 3 years ago

Hi Stephen,

Thanks.

Quick clarification. I changed the install of ambiorix in the dockerfile so it also installs Suggests. Thank you for pointing this out. This means that changes to the example should not be needed, ambiorix already checks that {mime} is installed and uses namespace to call its functions so there is no need to have it loaded in the global environment.