将SHINY R DataFrame插入到Db表中

时间:2016-05-18 09:11:28

标签: r vertica shiny

通过上传CSV文件创建数据框df1。 需要一些建议将上传的数据插入表格中。

library(shiny)
# use the below options code if you wish to increase the file input 
# limit, in this example file input limit is increased from 5MB to 9MB
# options(shiny.maxRequestSize = 9*1024^2)

shinyServer(function(input,output){

  # file$datapath -> gives the path of the file
  data <- reactive({
    file1 <- input$file
    if(is.null(file1)){return()} 
    read.table(file=file1$datapath, sep=input$sep, 
               header = input$header, stringsAsFactors = input$stringAsFactors)

  })


  output$filedf <- renderTable({
    if(is.null(data())){return ()}
    input$file
  })

  #DataFrame for input CSV
    df1<-reactive({
    if(is.null(data())){return ()}
    input$file
  })

  output$downloadbuttonstatus<-renderPrint({
    input$download
  })


  # This reactive output contains the dataset and display the dataset 
  # in table format
  output$table <- renderTable({
    if(is.null(data())){return ()}
    data()
  })


  completedQuery<-reactive({
    "**insert into Monetisation_Base_table VALUES()"**
  })

  ## Fire Query on Vertica Engine ##
  output$df2<-reactive({
    if (input$download == 0)
    {return()}
    else{
      Vertica_Connection <- odbcConnect("verticadsn")
      isolate({
        df2<-sqlQuery(Vertica_Connection,completedQuery())
      })
    }
  })


  # the following renderUI is used to dynamically generate the tabsets 
  # when the file is loaded. Until the file is loaded, app will not show the tabset.
  output$tb <- renderUI({
    if(is.null(data()))
      h5("Powered by", tags$img(src='RStudio-Ball.png', heigth=200, width=200))
    else
      tabsetPanel(tabPanel("About file", tableOutput("filedf")),tabPanel("Data", tableOutput("table")))
  })
})

0 个答案:

没有答案