私は光沢が新しく、私が欲しいことをするための解決策を見つけられませんでした。R、Shiny:selectInputの次/前のボタン
私の目的は、動的に作成された選択フィールド(selectInput)の[Previous/Next]ボタンを持つことです(データセットの機能によって選択肢が変わるため、今後の開発に必要です)。
私はこのポストAdd back/next button to date range input in shinyから自分自身をインスピレーションを受けました。
しかし私は私の場合も同じことをすることはできません。
ここでは簡単な例を試してみます(目的はこれをより複雑なデータセットに適用することです)。
library(shiny)
vector_choices <- seq(5, 50, by = 5)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
uiOutput("selector"),
tags$div(class="row",
tags$div(uiOutput("prevBin")),
tags$div(uiOutput("nextBin")))
),
mainPanel(
textOutput("text"),
plotOutput("distPlot")
)
)
)
server <- function(input, output, session) {
output$selector <- renderUI({
selectInput("bins",
"Bins",
choices = as.list(vector_choices),
selected = 25)
})
output$prevBin <- renderUI({
actionButton("prevBin",
label = "Previous")
})
output$nextBin <- renderUI({
actionButton("nextBin",
label = "Next")
})
observeEvent(input$prevBin, {
current <- which(vector_choices == input$bins)
if(current > 1){
updateSelectInput(session, "bins",
choices = as.list(vector_choices),
selected = vector_choices[current - 1])
}
})
observeEvent(input$nextBin, {
current <- which(vector_choices == input$bins)
if(current < length(vector_choices)){
updateSelectInput(session, "bins",
choices = as.list(vector_choices),
selected = vector_choices[current + 1])
}
})
output$distPlot <- renderPlot({
x <- rnorm(100)
bins <- seq(min(x), max(x), length.out = as.numeric(input$bins))
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
shinyApp(ui = ui, server = server)
誰もがこの問題に出くわしたか光沢のある専門家であり、それは非常に理解されるであろう正しい方向に私を指すことができます。
おかげ
編集:私はBigDataScientistの回答に基づいてコードを修正し、私は、リストの最初と最後の出現箇所の条件を追加しました。
パーフェクトこれが動作している、ありがとう! – Alexis