Search code examples
formsrr-rook-package

Populating an HTML dropdown box with an R vector


I am playing around with Rook and googleVis in an attempt to produce some interactive charts

I currently have an HTML text box where users can input a date to trigger changes

res <- Rook::Response$new()
res$write('<input type="text" name="theDate">')

I want to replace this with a combobox

res$write('<input type="dropdown" name="theDate">')

populated by an R vector similar to this

displayDates <- c("12 Mar 1980" ,"19 Mar 1980")

It is like a decade since I have done any of this HTML stuff and I'm also just beginning with Rook


Solution

  • Maybe something like this:

    library(Rook)
    dates <- c("12 Mar 1980" ,"19 Mar 1980")
    
    app <- function(env){
        req <- Rook::Request$new(env)
        res <- Rook::Response$new()
        res$write('<select>')
        res$write(paste("<option>", dates , "</option>"))
        res$write('</select>')
        res$finish()
    }
    
    s <- Rhttpd$new()
    s$launch(name="myapp", app=app)