代表 R 闪亮仪表板中信息框中的 selectInput 值

represent the selectInput value in an infoBox in R shiny dashboard

给定的 R shiny 脚本在下面有一个 selectInput 和信息框,我只想在 ui 的信息框内的 selectInput 中显示选定的值。请帮助我提供解决方案,如果可能的话,请避免在服务器中编写任何脚本,因为我有进一步的依赖性。如果这可以在 UI 内完成,那就太好了,谢谢。

## app.R ##
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
      fluidPage(
        fluidRow(

          column(2,offset = 0, style='padding:1px;',
                 selectInput("select the 
input","select1",unique(iris$Species)))
        ))),
  infoBox("Median Throughput Time", iris$Species)))
server <- function(input, output) { }
shinyApp(ui, server)

诀窍是确保您知道 selectInput 的值被分配到哪里,在我的示例中是 selected_data,这可以通过使用 [=13 在服务器代码中引用=].

renderUI 允许您构建一个动态元素,该元素可以使用 uiOutput 和输出 ID 呈现,在本例中为 info_box

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    box(title = "Data", status = "primary", solidHeader = T, width = 12,
        fluidPage(
          fluidRow(
            column(2, offset = 0, style = 'padding:1px;', 
                   selectInput(inputId = "selected_data",
                               label = "Select input",
                               choices = unique(iris$Species)))
            )
          )
        ),
    uiOutput("info_box")
    )
  )
# Define server logic required to draw a histogram
server <- function(input, output) {
   output$info_box <- renderUI({
     infoBox("Median Throughput Time", input$selected_data)
   })
}

# Run the application 
shinyApp(ui = ui, server = server)