Shiny如何处理批输入数据并返回表中的输出?

时间:2015-05-29 16:33:48

标签: html r shiny

我是新手。我正在尝试创建一个UI,允许用户批量粘贴数据,使用数据进行一些计算,然后将结果作为表返回,但我无法使输出表在这里工作。

我研究过textinput和shinyTable并最终选择了tags$textarea,因为这样我就可以批量输入了。但是我无法使用输入数据进行计算,我不知道如何解决这个问题。

enter image description here

代码段

ui.R

source("Assign Module.R")
tabPanel("Assign Module",
          sidebarLayout(
            sidebarPanel( "Property Locations",
                          helpText("Enter one address per line below"),
                          tags$style(type="text/css", 
                                     "textarea {width:100%}"),
                          tags$textarea('location', 
                                        placeholder = 'Paste here', 
                                        rows = 8, 
                                        ""),
                          br(),
                          actionButton("goButton", 
                                       "Go!")
            ),

            mainPanel(
              tableOutput('modules')
                      )

 ))

server.R

library(ggmap)
library(shiny)
  modules <- eventReactive(input$goButton, {
    geocode<-geocode(as.character(input$location))
    m<-getmodules(geocode)
    df<-cbind(input$location,m)
    return(df)
  })

  output$modules <- renderTable({
    modules()
  })

分配Module.R

centers <- aggregate(cbind(data.t$Latitude,data.t$Longitude)~data.t$Cluster, FUN=mean)
n.cluster=nrow(centers)
R <- 3958.756 # Earth mean radius [miles]

radians = function(theta=0){return(theta * pi / 180)}   #convert to radians

dist <- function(xind, yind)    # Define the Grear Circle Distance function
  acos(sin(G[xind, 1]) * sin(C[yind, 1]) + 
         cos(G[xind, 1]) * cos(C[yind, 1]) * cos(C[yind, 2] - G[xind, 2])) * R

modules<-function(df){
  n.row=nrow(df)
  G <- radians(df[,c(2,1)])
  C <- radians(centers[,c(2,3)])    
  dist_mat<- outer(seq.int(n.row), seq.int(n.cluster), dist)
  modules <- apply(dist_mat,MARGIN=1,which.min)

  return(modules)
}

示例输入

10 E. Delaware Place,   Chicago,    IL  60611
100 Arbor Court,    Wheeling,   IL  60090
100 Center Street,  Mishawaka,  IN  46544
100 Forest Avenue,  Oak Park,   IL  60301
1000 W. Washington Boulevard,   Chicago,    IL  60607
1000 Waukegan Rd.,  Deerfield,  IL  60015
1000-1010 N. Lake Shore Drive,  Chicago,    IL  60611

如果需要任何信息,请告诉我。任何帮助表示赞赏!

0 个答案:

没有答案
相关问题