我正在考虑使用 package.json 将数据库中的数据直接导入到 r 中RPostgresQL。到目前为止,我曾经在Postico(PostgreSQL 客户端)软件中编写查询并导出为 csv,然后将 csv 文件导入 R。
这是我到目前为止所写的内容,不知道下一步如何进行。
library('RPostgreSQL')
pg=dbDriver("PostgreSQL")
con = dbConnect(pg, user="msahil515", password="",
host="localhost", port=5432, dbname="msahil515")
Run Code Online (Sandbox Code Playgroud)
在此之后如何将数据库中的表加载到 R 中,或者如何在 R 中编写查询以仅从数据库中提取必要的数据?
我有一个闪亮的模块,它显示一个带有评论列的表格,用户可以在客户端输入文本,然后评论将存储在数据库中。现在,我想添加另一列带有复选框并将其相应的值(TRUE/FALSE)存储在数据库中。不确定如何从表中检索复选框值。以下是我对示例数据的尝试。
library(tidyverse)
library(shinyWidgets)
library(shiny)
library(htmlwidgets)
mtcars_df <- mtcars %>%
rownames_to_column(var="car")
writeback_UI <- function (id) {
ns <- NS(id)
DT::dataTableOutput(ns('records_tbl'))
}
shinyInput = function(FUN, len, id, ...) {
inputs = character(len)
for (i in seq_len(len)) {
inputs[i] = as.character(FUN(paste0(id, i), label = NULL, ...))
}
inputs
}
# obtain the values of inputs
shinyValue = function(id, len) {
unlist(lapply(seq_len(len), function(i) {
value = input[[paste0(id, i)]]
if (is.null(value)) NA else value
}))
}
writeback_server <- function (id,records_data) {
#stopifnot(is.reactive(records_data))
shiny::moduleServer(id, function (input,output,session) …Run Code Online (Sandbox Code Playgroud)