4

In ui.R, I put:

uiOutput("singlefactor")

In server.R, I have:

  output$singlefactor <- renderUI({
    selectInput("sfactor", "Feature selection:", names(datatable()))
  })

Using these, I can show the column names of the data.frame datatable() in the select menu. What I want to do next is:

Let's say the column names are a, b, c, d in datatable(). I pick a from ui.R, then, a is sent back to server so that I can use the subset of datatable() that only includes a for the next calculation.

So, my question is: how can I send a back to server.R?

Feng Chen
  • 2,139
  • 4
  • 33
  • 62
  • Just create a variable that listens for `input$sfactor`. Something like `my_var <- reactive({if (is.null (input$sfactor)) return(NULL) else return(input$sfactor)})`. Then you can just call that variable anywhere with `my_var()`. Or, just use `input$sfactor`. – tblznbits Dec 25 '15 at 04:13

1 Answers1

10

The value will be available like any other input, for example

library(shiny)

runApp(list(ui=shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(
      uiOutput("singlefactor")
    ),
    mainPanel(
      plotOutput("distPlot")

    )
  )
))
,
server=shinyServer(function(input, output) {
     output$singlefactor <- renderUI({
    selectInput("sfactor", "Feature selection:", names(mtcars))
  })
  output$distPlot <- renderPlot({plot(mtcars[,input$sfactor])})

})
))

You created a UI element with the name "sfactor" so you can get the value with input$sfactor

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Yeah, it totally works! thanks a lot. I am totally new for shiny. So maybe there are a lot of issues that is difficult for me. – Feng Chen Dec 25 '15 at 04:21