【发布时间】:2021-12-19 12:20:06
【问题描述】:
无可否认,我已经设法获得了这个非常基本的表格,可以使用 invalidateLater() 函数自行更新,并且在按下刷新按钮时也可以更新,但是,我没有设法将它们结合起来,表格将更新每个给定的时间段或当用户按下按钮时。请你帮帮我,我在下面添加了我的代码!
if (interactive()) {
# table example
shinyApp(
ui = fluidPage(
fluidRow(
column(12,
tableOutput('table'),
actionButton("refresh", "Update")
)
)
),
server = function(input, output) {
observeEvent(input$refresh, {
invalidateLater(15000)
spot_gold <- fromJSON("https://api.metals.live/v1/spot")[[1]][[1]]
spot_silver <- fromJSON("https://api.metals.live/v1/spot")[[2]][[1]]
spot_platinum <- fromJSON("https://api.metals.live/v1/spot")[[3]][[1]]
spot_palladium <- fromJSON("https://api.metals.live/v1/spot")[[4]][[1]]
spot_prices <- cbind(spot_gold, spot_silver, spot_platinum, spot_palladium)
output$table <- renderTable(spot_prices)
})
}
)
}
【问题讨论】:
标签: r api shiny shiny-reactivity