将google api的地址自动完成功能的响应添加到R中的shinyapp中

时间:2016-05-17 16:17:58

标签: javascript r reactive-programming shiny

我希望将javascript+html script中的自动完成功能填写的地址添加到Shiny中的textInput()框中。此外,一旦我提交了具有该地址的表单,我希望重置自动完成的地址。我有一些Shiny / R的经验,但在Js中没有。我相当肯定我需要在js中添加一些行来向Shiny发送信息,但我不确定如何。我的脚本如下:

library(shiny)
library(googlesheets)
library(DT)

# Define the fields we want to save from the form
fields <- c("Title", "Description", "Order Type", "Existing", "Due Date", "Address")

gs_auth()
table <- "responses"

saveData <- function(data) {
  # Grab the Google Sheet
  sheet <- gs_title(table)
  # Add the data as a new row
  gs_add_row(sheet, input = data)
}

# Load all previous responses
# ---- This is one of the two functions we will change for every storage type ----

loadData <- function() {
  # Grab the Google Sheet
  sheet <- gs_title(table)
  # Read the data
  gs_read_csv(sheet)
}

# Shiny app with 3 fields that the user can submit data for
shinyApp(
  ui = fluidPage(
    titlePanel("Sign Form"),
    fluidRow(
    DT::dataTableOutput("responses", width = 300), tags$hr(),
    column(3, textInput("Title", "Title", "")),
    column(3, textInput("Description", "Description", "")),



    column(3, selectInput("Order Type", label = ("Select Box"), choices = list("Installation", 
                                                                "Installation/Maintenance",
                                                                "Replace Existing")))


    ),

    fluidRow(
      column(3,checkboxInput("Existing", "Is there an existing sign", FALSE)),
      column(3, dateInput("Due Date", label = ('Date input'), format = "mm-dd-yyyy"))
    ),
    fluidRow(
      **column(3, textInput("Address","Address", includeHTML("www/autocomplete.html")))**


    ),
    fluidRow(
      column(3, actionButton("submit", "Submit"))
    )
  ),
  server = function(input, output, session) {

    # Whenever a field is filled, aggregate all form data
    formData <- reactive({
      data <- sapply(fields, function(x) input[[x]])
      data
    })

    # When the Submit button is clicked, save the form data
    observeEvent(input$submit, {
      saveData(formData())
    })

    # Show the previous responses
    # (update with current response when Submit is clicked)
    output$responses <- DT::renderDataTable({
      input$submit
      loadData()
    })     
  }
)

使用autocomplete.html的行是我希望在最终用户填写地址表时填充的某种textInput()

以下是autocomplete.html文件的示例&#34; Javascript + HTML&#34;

0 个答案:

没有答案