表示R闪亮仪表板中infoBox中的selectInput值

时间:2018-01-29 05:28:46

标签: r shiny shinydashboard shinyapps

给定的R闪亮脚本下面有一个selectInput和infobox,我只想在ui的信息框中的selectInput中显示所选的值。请帮助我解决方案,如果可能的话,请避免在服务器上编写任何脚本,因为我有依赖性。如果这可以在用户界面中完成,那就太棒了,谢谢。

## 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

1 个答案:

答案 0 :(得分:1)

Trick是为了确保您知道selectInput的值的分配位置,在我的示例中为selected_data,可以使用input$selected_data在服务器代码中引用

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)