r - 将 R obect 直接保存到 Dropbox
问题描述
我正在寻找一种将工作簿从 R 保存到 DropBox 的方法,而不必先在本地保存它们。这很重要,因为我想在闪亮的应用程序中使用它,用户将数据添加到表中,然后必须上传表。下面是一个示例应用程序,只是为了说明问题。
library(shiny)
library(DT)
library(rdrop2)
library(writexl)
drop_read_excel <- function(file, dest = tempdir(), dtoken = rdrop2:::get_dropbox_token(), ...) {
localfile <- paste0(dest, "/", basename(file))
drop_download(file, localfile, overwrite = TRUE, dtoken = dtoken)
readxl::read_excel(localfile, ...)
}
token <- readRDS("drop_token.rds")
drop_acc(dtoken = token)
drop_auth(rdstoken = "drop_token.rds")
drop_dir("e2")
ui <- fluidPage(
titlePanel("UC Berkley Admissions"),
mainPanel(
tabsetPanel(
id = "dataset",
tabPanel(
"Sample Bank",
DT::dataTableOutput("banking.df_data"),
br(),
actionButton("viewBtn", "View"),
br(),
actionButton("saveBtn", "Save"),
br(),
DT::dataTableOutput("updated.df")
)
)
)
)
server <- function(input, output) {
d1 <- data.frame(drop_read_excel("e2/dd/test.xlsx"))
output$banking.df_data <- renderDataTable(
d1,
selection = "none", editable = TRUE,
rownames = TRUE,
extensions = "Buttons",
options = list(
paging = TRUE,
searching = TRUE,
fixedColumns = TRUE,
autoWidth = TRUE,
ordering = TRUE,
dom = "Bfrtip",
buttons = c("csv", "excel")
),
class = "display"
)
observeEvent(input$banking.df_data_cell_edit, {
d1[input$banking.df_data_cell_edit$row, input$banking.df_data_cell_edit$col] <<- input$banking.df_data_cell_edit$value
})
view_fun <- eventReactive(input$viewBtn, {
if (is.null(input$saveBtn) || input$saveBtn == 0) {
returnValue()
}
else {
DT::datatable(d1, selection = "none")
}
})
observeEvent(input$saveBtn, {
**### !!! I need to save locally first to upload it. Is there a way to uploadit directly to dropbox???**
write_xlsx(d1, "test2.xlsx")
drop_upload("test2.xlsx", path = "e2/dd")
})
output$updated.df <- renderDataTable({
view_fun()
})
}
shinyApp(ui = ui, server = server)
解决方案
推荐阅读
- java - Java中引用变量的枚举
- r - 单细胞实验。为什么我在单细胞实验中没有成功更改行名和列名?
- javascript - 如何从 Cloud Firestore 数据库中检索所有文档(包含图像 url 和名称)到网站?
- python - 如何在没有空格的文本列中查找所有文本
- excel - 获取“运行时错误'1004':范围类的选择方法失败”
- c++ - 为什么 moc 错误不是由纯方法引起的?
- cakephp - CakePHP 3.x 关于订单的 case 语句
- java - java.io.FileNotFoundException:打开失败:EISDIR(是一个目录)
- python - 输入在 VS Code 中可用?
- server - 带有 BI 应用程序的服务器每天在固定时间停机