【发布时间】:2018-06-20 22:35:18
【问题描述】:
我一直在摸索着想弄清楚这一点。
所以我已经连接到数据库,但是当我按下操作按钮时,表格没有发生任何事情。
CSV 正在转换为数据框。
用户界面
library(shiny)
library(RJDBC)
library(dbtools)
library(jsonlite)
library(shinyjs)
library(DBI)
# App title ----
titlePanel("Uploading Files"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Select a file ----
fileInput("file1", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
tags$head(
tags$style(HTML(
'#Uploadbutton{background-color:cyan}'
))
),
actionButton("Uploadbutton","Upload"),
p("Upload Members if data looks ok")
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Data file ----
tableOutput("contents")
)
)
)
服务器
server <- function(input, output) {
output$contents <- renderTable({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, head of that data file by default,
# or all rows if selected, will be shown.
req(input$file1)
data <- read.csv(input$file1$datapath,header=TRUE)
if(input$disp == "head") {
return(head(data))
}
else {
return(data)
}
data <- data.frame()
data <<- read.csv(input$file1$datapath,header=TRUE)
testdata <- read.csv("data",sep=",",row.names=1)
observeEvent(input$Uploadbutton, {
insert_into("data", "ANALYTICS.TEST_DATASTORE", con=lol, rows_per_statement=1)
})
}
)
【问题讨论】:
-
insert_into()是您自己的用户定义方法还是来自 R 库? -
这是一个名为 dbtools 的包。数据库在 db2 上,是否有替代包可供使用。
-
认为它是一个被修改的内部包(员工离开公司),还有什么其他包做同样的工作?
-
请在实际帖子中包含
library行。请参阅 编辑 链接。然后删除你上面的评论。还有什么套餐?查看您用于插入过程的库的文档,但您需要遍历数据框行!对于 DB2,将需要 RJDBC。 -
但是,虽然我无法确定
insert_into,但请检查参数。没有你在哪里拉入数据框对象,data(未引用)。看看如何在这个方法中定义源表和目标表。
标签: sql r database dataframe shiny