在shiny
应用中,我想要包含动画tabBox
,类似于动画sliderInput
- 在指定时间后,标签会自动切换到下一个。这似乎不是tabBox
中的一个选项。我试过两个解决方案,但都没有用。首先,我尝试将动画从sliderInput
链接到tabBox
:
library("shiny")
library("shinydashboard")
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sliderInput(inputId = "slider", label = "Player", min = 1, max = 4, value = 1,
animate = animationOptions(interval = 1000, loop = TRUE)),
textOutput(outputId = "text")
),
dashboardBody(
tabBox(
id="tabbox",
tabPanel(title = 1),
tabPanel(title = 2),
tabPanel(title = 3),
tabPanel(title = 4)
)
)
)
)
server <- function(input, output, session){
output$text <- renderText({paste0("tabbox: ", input$tabbox, " slider: ",input$slider, " reactive: ", A$a)})
A <- reactiveValues(a = 1)
observeEvent(
input$slider,
A$a <- input$slider
updateTabItems(session = session, inputId = "tabbox", selected = A$a)
)
}
shinyApp(ui=ui, server=server)
但是,此代码仅更改了被动值A$a
,但未更改input$tabbox
(A$a
只有这样我才能看到哪一步失败了。)
我尝试的第二个解决方案是在按钮点击时运行此功能,但它也失败了:
for(i in 1:4){
Sys.sleep(2)
updateTabItems(session = session, inputId = "tabbox", selected = i)
}
问题:
只用R就可以吗?怎么可能呢?