Haribo
Haribo

Reputation: 2226

Call an input object from selectInput in UI

I'm using shinydashboard package to create a shiny app.

In UI function I have a selectInput, which I would like to use those input later on in the box title but I don't know how could I access them I have tried input$xx, input.xx and 'input.xx' but it does not work :

dashboardSidebar(
selectInput("wind","Select Wind speed",choices = c(6,8,10,12),selected = 10),
selectInput("time","Select Time",choices = c(2,3,4),selected = 3),
downloadButton('report')
                  ),
                  dashboardBody(
                  fluidRow(
                       box(width = 12,title = paste("time :", "'input$time'" ,"and wind speed :", "'input$wind'" ,"m/s are recorded."),
                       column(12,withSpinner(tableOutput("tab6"),type=5))
                               )
                             )

                           )

Upvotes: 1

Views: 508

Answers (2)

Haribo
Haribo

Reputation: 2226

I have found the sloution :

Using RenderUI function :

in UI :

dashboardBody(
uiOutput("txt")
              )

And in server :

output$txt <- renderUI({
  fluidRow(

    box(width = 12,title = paste("time :", input$time ,"and wind speed :", input$wind ,"m/s are recorded."),
    column(12,withSpinner(tableOutput("tab6"),type=5))
    ),
    box(width = 12,
    column(12,withSpinner(tableOutput("tab3"),type=5))
    )
  )
})

Upvotes: 1

gabzo
gabzo

Reputation: 238

This is how I would approach your issue. Firstly you need to use the "updateTextInput" function of shiny. More details here: https://shiny.rstudio.com/reference/shiny/1.0.2/updateTextInput.html

Here is how your code should look like:

ui <- dashboardPage(
                    dashboardHeader(title = "Control Panel"),
                    dashboardSidebar(
                      selectInput("wind","Select Wind speed",choices = c(6,8,10,12),selected = 10),
                      selectInput("time","Select Time",choices = c(2,3,4),selected = 3),
                      downloadButton('report')
                    ),
                    dashboardBody(
                      fluidRow(
                        column(12,textInput("inText", "Text1"))
                        )
                      )

                    )
                    )


# 2. Server ---------------------------------------------------------------
server <- function(input, output, session){

  observe({
    x <- input$time
    y <- input$wind

    updateTextInput(session, "inText", value = paste("time :", x ,"and wind speed :", y ,"m/s are recorded."))


  })

}

# 3. App ------------------------------------------------------------------
shinyApp(ui, server)

Upvotes: 0

Related Questions