我正在尝试将Paypal集成到R Shiny应用程序中。 我已成功设置了沙盒并确认了付款。 但是,我无法弄清楚如何使应用程序在成功付款后立即下载CSV文件或显示一个新按钮以允许下载。 基本上,我想按每次下载我的清理数据集的便宜价格收费,并将其保存为CSV格式。以下是UI /服务器部分,包括我尝试过的某些反应性东西(我一直在尝试使用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。