R 显示ActionButton旁边选中的框总数

R 显示ActionButton旁边选中的框总数,r,shiny,R,Shiny,我有一列复选框。我想添加选中框数的运行总数,并将其显示在“操作”按钮旁边(而不是下方)。比如: 选中的选项:(最大值=10) 我该怎么做 library(shiny) library(tidyverse) df <- tibble( state = c("Alabama", "Alaska", "Arizona", "Arkansas", "California"

我有一列复选框。我想添加选中框数的运行总数,并将其显示在“操作”按钮旁边(而不是下方)。比如:

选中的选项:(最大值=10)

我该怎么做

library(shiny)
library(tidyverse)

df <- tibble(
  state = c("Alabama", "Alaska", "Arizona", "Arkansas",
            "California", "Colorado", "Connecticut", "Delaware", "Florida"),
  abr = c("AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL")
)

selected_states <- c("AL", "AK","DE")

ui <- fluidPage(
  
  wellPanel(
    tags$label("Choose :"),
    fluidRow(
      column(
        width = 4,
        checkboxGroupInput(
          selected = df$abr[1:3],
          inputId = "checka",
          label = NULL,
          choiceNames = df$state,
          choiceValues = df$abr
          #choices = df$state
        ),
        actionButton("update", "Update", class = "btn-primary", width = 250, 
                     style="color: #FFF; background-color: #525252;"),
        # textOutput("selected"),
        hr()
      ),
      
    )
  )
)

server <- function(input, output, session) {
  observeEvent(input$all_none,{
    updateCheckboxGroupInput(
      session, 'checka', choiceNames = df$state, choiceValues = df$abr,
      selected = if (input$all_none == TRUE) df$state
    ) 

  }, ignoreInit = 1)
  
  output$selected <- renderText({
    all_selected <- paste(c(input$checka), collapse = ", ")
  })
}

shinyApp(ui, server)
库(闪亮)
图书馆(tidyverse)

df您可以尝试使用splitLayout

library(shiny)
library(tidyverse)

df <- tibble(
  state = c("Alabama", "Alaska", "Arizona", "Arkansas",
            "California", "Colorado", "Connecticut", "Delaware", "Florida"),
  abr = c("AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL")
)

selected_states <- c("AL", "AK","DE")

ui <- fluidPage(
  
  wellPanel(
    tags$label("Choose :"),
    fluidRow(
      column(
        width = 4,
        checkboxGroupInput(
          selected = df$abr[1:3],
          inputId = "checka",
          label = NULL,
          choiceNames = df$state,
          choiceValues = df$abr
          #choices = df$state
        )
      ),
      
    ),
    splitLayout(cellWidths = c(250,"50%"),
                actionButton("update", "Update", class = "btn-primary", width = 250, 
                             style="color: #FFF; background-color: #525252;"),
                h4(textOutput("selected"))
    ),
    hr()
  )
)

server <- function(input, output, session) {
  observeEvent(input$all_none,{
    updateCheckboxGroupInput(
      session, 'checka', choiceNames = df$state, choiceValues = df$abr,
      selected = if (input$all_none == TRUE) df$state
    ) 
    
  }, ignoreInit = 1)
  
  output$selected <- renderText({
    all_selected <- paste0("Options checked:", length(c(input$checka)), " (Max = ", length(df$state) , ")")
  })
}

shinyApp(ui, se
库(闪亮)
图书馆(tidyverse)

df您可以尝试使用splitLayout

library(shiny)
library(tidyverse)

df <- tibble(
  state = c("Alabama", "Alaska", "Arizona", "Arkansas",
            "California", "Colorado", "Connecticut", "Delaware", "Florida"),
  abr = c("AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL")
)

selected_states <- c("AL", "AK","DE")

ui <- fluidPage(
  
  wellPanel(
    tags$label("Choose :"),
    fluidRow(
      column(
        width = 4,
        checkboxGroupInput(
          selected = df$abr[1:3],
          inputId = "checka",
          label = NULL,
          choiceNames = df$state,
          choiceValues = df$abr
          #choices = df$state
        )
      ),
      
    ),
    splitLayout(cellWidths = c(250,"50%"),
                actionButton("update", "Update", class = "btn-primary", width = 250, 
                             style="color: #FFF; background-color: #525252;"),
                h4(textOutput("selected"))
    ),
    hr()
  )
)

server <- function(input, output, session) {
  observeEvent(input$all_none,{
    updateCheckboxGroupInput(
      session, 'checka', choiceNames = df$state, choiceValues = df$abr,
      selected = if (input$all_none == TRUE) df$state
    ) 
    
  }, ignoreInit = 1)
  
  output$selected <- renderText({
    all_selected <- paste0("Options checked:", length(c(input$checka)), " (Max = ", length(df$state) , ")")
  })
}

shinyApp(ui, se
库(闪亮)
图书馆(tidyverse)

df代码的服务器部分在哪里?在那里。这是我机器上的一个可滚动窗口。哎呀,由于某种原因,我无法向下滚动。:)代码的服务器部分在哪里?在那里。这是我机器上的一个可滚动窗口。哎呀,不知什么原因,我无法向下滚动。:)