【问题标题】:How to Download excel File after successful Paypal transaction R ShinyPaypal交易成功后如何下载excel文件 R Shiny
【发布时间】:2020-09-10 07:11:49
【问题描述】:

我正在尝试将 Paypal 集成到 R Shiny 应用程序中。我已成功设置沙盒并确认付款。但是,我不太清楚如何让应用程序立即下载 csv 文件或在成功付款后显示一个新按钮以允许下载。基本上,我想在每次下载我清理的数据集作为 csv 时收取便宜的费用。以下是 ui/server 部分,包括我尝试过的一些反应性的东西(我一直在尝试使用 shinyJS 来绕过它但无济于事)。

#ui
fluidRow(
        column(width = 12,
               boxPlus(
                 title = 'Bulk Financial Download - By Ticker',
                 closable = FALSE,
                 width = 12,
                 status = "info",
                 solidHeader = FALSE,
                 collapsible = TRUE,
                 enable_dropdown = FALSE,
                 fluidRow(
                   column(width = 3,
                 actionButton("Calculate", 
                              label = ui <- fluidPage(
                                tags$script(src = "https://www.paypalobjects.com/api/checkout.js "),
                                tags$script("paypal.Button.render({
                                // Configure environment
                                env: 'sandbox',
                                client: {
                                sandbox: 'hidden',
                                production: 'demo_production_client_id'
                                },
                                // Customize button (optional)
                                locale: 'en_US',
                                style: {
                                size: 'small',
                                color: 'gold',
                                shape: 'pill',
                                },
                                // Set up a payment
                                payment: function (data, actions) {
                                return actions.payment.create({
                                transactions: [{
                                amount: {
                                total: '0.01',
                                currency: 'USD'
                                }
                                }]
                                });
                                },
                                // Execute the payment
                                onAuthorize: function (data, actions) {
                                return actions.payment.execute()
                                .then(function () {
                                // Show a confirmation message to the buyer
                                window.alert('Thank you for your purchase!');
                                });
                                }
                                }, '#Calculate');"),
                                tags$div(id = "Calculate")))
                 ),
                 column(
                   width =3,
                 hidden(div(
                   id='actions',
                 downloadButton("downloadData", "Download")
                 ))
                 )
                 )
               )
               )
      )
#server
    shinyjs::hide('actions')


    observeEvent(input$Calculate, {
      shinyjs::hide('Calculate')
      shinyjs::show('actions')
    })

    observeEvent(input$ticker, {

      shinyjs::hide('actions')
      shinyjs::show('Calculate')
    })

     output$downloadData <- downloadHandler(
    filename = function() {
      paste(stockInfo()$symbol, "financials.csv", sep = "")
    },
    content = function(file) {
      write.csv(tables(), file, row.names = FALSE)
    }
  )

到目前为止,在我的尝试中,Paypal 按钮周围有一个按钮可以激活shinyjs 显示或隐藏,但是当我直接单击 Paypal 按钮而不是实际付款时,什么也没有发生。我也在使用 shinydashboard 和 shinydashboardPlus。

【问题讨论】:

  • 我认为一种方法是将自定义消息放入 onAuthorize 回调函数中。然后,让 Shiny 收听,如果成功,使用 RenderUI 或条件显示下载按钮。但如果有人能想出一个完整的解决方案,那就太好了!

标签: r paypal shiny shinydashboard


【解决方案1】:

我有一个类似的挑战,希望我闪亮的应用程序的一部分对成功的贝宝付款做出反应。我在这里找到了解决方案:

https://shiny.rstudio.com/articles/communicating-with-js.html

在我包含添加 PayPal 结帐按钮的代码的 UI 中,我使用“setInputValue”函数添加了一行:

window.alert('Thank you for your purchase!');
Shiny.setInputValue('payment', 'success');

然后在服务器端,我使用事件观察器来显示两种可能的输出之一:

  observeEvent(input$payment,{
      if(input$payment!='success'){
        output$mymap <- renderLeaflet({
          Option A
        })
       } else if(input$payment=='success'){
        output$mymap <- renderLeaflet({
          Option B
        })
      }
   })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 2021-12-20
    • 2014-02-18
    • 1970-01-01
    • 2016-01-31
    • 2012-08-03
    相关资源
    最近更新 更多