从数据表中选择多行并保存在GoogleSheets中。

问题描述 投票:0回答:1

我正在做一个从API中拉取数据的应用程序,我的下一个目标是点击数据表中的多行,并将所有选中的行保存在连接的Google Sheet中,这就是我被卡住的地方。我的下一个目标是点击数据表中的多行,并将所有选择的行保存在连接的Google Sheet中,这就是我被卡住的地方。我不知道如何选择数据的方式,使它被存储在另一个变量中,我以后可以将其发送到Google Sheet或其他数据库中。

library(shiny)
library(jsonlite)
library(tidyverse)
library(shinydashboard)
library(DT)

ui <- dashboardPage(
    dashboardHeader(title = "APPLICATION"),
    dashboardSidebar(
        sidebarMenu(
            menuItem('Menu', tabName='menu',
                     menuSubItem('Select Data', tabName='tab1'),
                     menuSubItem('Selected Data', tabName='tab2')
            )
        )
    ),

    dashboardBody(

        tabItems(
            tabItem(tabName='tab1',
                    textInput('usernameinput', 'Username:', 'Username'),
                    actionButton("search", "Search", class = "btn btn-info"),
                    br(),
                    tags$div(tags$h3(tags$b(" Select Data",align="middle",style="color: rgb(57,156,8)"))),
                    br(),
                    DT::dataTableOutput('table')
            ),
            tabItem(tabName='tab2'
            )
        )
    )
)

server <- function(input, output, session) {

    observeEvent(input$search, {
    url <- paste0("https://API-LINK/", input$usernameinput)
    link <- fromJSON(url, flatten=T)
    data <- as.data.frame(link$results)


    output$table <- renderDataTable({

        DT::datatable(data,selection = "multiple",

                      extensions = c('Buttons', 'ColReorder', 'FixedHeader', 'Scroller'),
                      rownames=FALSE,
                      options=list(dom = 'Bfrtip',
                                   searching = T,
                                   pageLength = 25,
                                   searchHighlight = TRUE,
                                   colReorder = TRUE,
                                   fixedHeader = TRUE,
                                   filter = 'bottom',
                                   buttons = c('copy', 'csv','excel', 'print'),
                                   paging    = TRUE,
                                   deferRender = TRUE,
                                   scroller = TRUE,
                                   scrollX = TRUE,
                                   scrollY = 700
                                   ))
                                }) 

    })
    # print the selected indices
    output$selected = renderPrint({
        s = input$ListingID
        if (length(s)) {
            cat('These rows were selected:\n\n')
            cat(s, sep = ', ')
        }
    })
}

shinyApp(ui, server)

r datatable shiny dt
1个回答
0
投票

关于访问和操作数据... ...

1 - 你是想创建一个客户端用户可以使用的应用程序,还是想为自己的使用分析收集数据?

2 - 是通过API来获取数据的唯一途径吗?

3 - 数据是在MS SQL数据库或MySQL中,还是你在收集数据或什么?

4 - 你可以登录到数据库,并使用一个工具,如phpMyAdmin或MySQL工作台?

5 - 使用API,你可以以任何形式获得数据...比如显示在你的屏幕上或下载它或什么?

© www.soinside.com 2019 - 2024. All rights reserved.