0

The given R shiny script has a selectInput and infobox below, I just want to display the selected value in the selectInput within the infobox in the ui. Please help me with a solution and if possible, kindly avoid any scripting in the sever as I have furthur dependency. If this can be done within the UI, would be great, thanks.

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

Adam Shaw
  • 519
  • 9
  • 24

1 Answers1

1

Trick is to make sure you know where the value of the selectInput is being assigned, which is selected_data in my example, this can be referenced within the server code by using input$selected_data.

renderUI lets you build a dynamic element which can be rendered with uiOutput and the output id, in this case, 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)
zacdav
  • 4,603
  • 2
  • 16
  • 37
  • @zacdev, thank you so much for the help, however, as I have mentioned furthur dependancy, I have a requirement where the same uiOutput has to be replicated for multiple tabs, kindly check this question and help me with a fix if possible. Thanks. – Adam Shaw Jan 29 '18 at 07:34
  • @AdamShaw you should be able to just copy the code and adjust OR add `if` and `else` statements in the `renderUI` call depending on the selected tab, this can be done - would just need more context on what is being done. – zacdav Jan 29 '18 at 07:42
  • please check the link here, https://stackoverflow.com/questions/48496426/display-the-selectinput-value-in-a-r-shiny-widget-box – Adam Shaw Jan 29 '18 at 07:44
  • I hope this might give a lot of clarity, basically I am using shinyModules, so wish to display the selected value of the selectInput in the shinywidget below. – Adam Shaw Jan 29 '18 at 08:11