gpt4 book ai didi

r - Paypal交易成功后如何下载excel文件 R Shiny

转载 作者:行者123 更新时间:2023-12-03 20:53:08 28 4
gpt4 key购买 nike

我正在尝试将 Paypal 集成到 R Shiny 应用程序中。我已成功设置沙箱并确认付款。但是,我不太清楚如何让应用程序立即下载 csv 文件或在成功付款后显示一个新按钮以允许下载。基本上,我想每次下载我的清理数据集作为 csv 收取便宜的费用。这是 ui/server 部分,包括我尝试过的一些 react 性的东西(我一直在尝试使用 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。

最佳答案

我遇到了类似的挑战,希望我 Shiny 的应用程序的一部分对成功的 Paypal 付款使用react。我在这里找到了我的解决方案:
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
})
}
})

关于r - Paypal交易成功后如何下载excel文件 R Shiny,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61972059/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com