在 Shiny 中,我使用带有大量项目的水平 radioGroupButtons 输入。如果单击其中一项,按钮标签的颜色会发生变化。这实际上很好。
但是,如果我单击最后一项以使我向右滚动很远,则滚动位置将重置。
所以每次点击后,如果我想继续下一个项目,我必须再次向右移动。
是否有解决方案可以在每次单击后保留滚动位置?
这是代码:
library(shiny)
library(shinyWidgets)
ui <- fluidPage(uiOutput("selItem"))
server <- function(input, output, session)
{
global <- reactiveValues(itemNames=NULL, itemValues=NULL)
observe(
{
options <- c("word01", "word02", "word03", "word04", "word05", "word06", "word07", "word08", "word09", "word10", "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", "word20", "word21", "word22", "word23", "word24", "word25", "word26", "word27", "word28", "word29", "word30", "word31", "word32", "word33", "word34", "word35", "word36","word37", "word38", "word38", "word39", "word40", "word41", "word42", "word43", "word44", "word45", "word46", "word47")
global$itemNames = options
global$itemValues = options
})
output$selItem <- renderUI(
{
fluidRow(
style = "overflow-x: scroll;",
radioGroupButtons(inputId = "replyItem", label = NULL, choiceNames = global$itemNames, choiceValues = global$itemValues, selected = character(0), individual = TRUE, width = "10000px")
)
})
observeEvent(input$replyItem,
{
index <- which(global$itemValues==input$replyItem)
global$itemNames[index] <- HTML(paste0("<span style='color: #0000ff'>", global$itemValues[index], "</span>"))
})
}
shinyApp(ui = ui, server = server)