bda*_*002 5 paypal r shiny shinydashboard
我正在尝试将 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")
))
)
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
#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)
}
)
Run Code Online (Sandbox Code Playgroud)
到目前为止,在我的尝试中,发生的情况是 Paypal 按钮周围有一个按钮可以激活shinyjs 显示或隐藏,但是当我直接单击 Paypal 按钮而不是实际付款时,什么也没有发生。我也在使用shinydashboard和shinydashboardPlus。
小智 0
我遇到了一些类似的挑战,希望我的闪亮应用程序的一部分能够对成功的贝宝付款做出反应。我在这里找到了我的解决方案:
https://shiny.rstudio.com/articles/communicating-with-js.html
在我的 UI 中,我添加了添加 PayPal 结帐按钮的代码,我使用“setInputValue”函数添加了一行:
window.alert('Thank you for your purchase!');
Shiny.setInputValue('payment', 'success');
Run Code Online (Sandbox Code Playgroud)
然后在服务器端,我使用事件观察器来显示两种可能的输出之一:
observeEvent(input$payment,{
if(input$payment!='success'){
output$mymap <- renderLeaflet({
Option A
})
} else if(input$payment=='success'){
output$mymap <- renderLeaflet({
Option B
})
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
431 次 |
| 最近记录: |