0

I am taking significant variables from ML model(.rda file),putting them as numericInput box or selectInput Option menu in the UI page. I am getting each Input in different row. I want it as two columns in a row. How can I do that? I am getting it as shown in the image

Below is the code which I want to modify.

 model <- reactive({readRDS(input$Load_model$datapath)})
  temp_col <- reactive({colnames(model()$model)})
  temp_no_col <- reactive({ncol(model()$model)})

  abc <- reactive(lapply(model()$model, class))
  process <- eventReactive(input$show_fields, {
    lapply(1:(temp_no_col()), function(i) {
        if(abc()[i] == "numeric" ) {
          numericInput(temp_col()[i], label = temp_col()[i],value = 0)
        }
        else if(abc()[i] == "factor") {
          selectInput(temp_col()[i], label = temp_col()[i],choices = unique(model()$model[i]))
        }
    })
  })
Ganesa Vijayakumar
  • 2,422
  • 5
  • 28
  • 41
  • Please see the [shiny layout guide](https://shiny.rstudio.com/articles/layout-guide.html). Especially the section 'Grid Layout' and the `column()` function. – ismirsehregal Nov 25 '19 at 09:08

1 Answers1

0

As @ismirsehregal says in the comments, you need to take a look at the shiny layout guide. You are creating the inputs programmaticaly, with lapply, so you need to dispatch the inputs created into two columns, something like this:

process <- eventReactive(input$show_fields, {
  inputs_temp <- lapply(1:(temp_no_col()), function(i) {
    if(abc()[i] == "numeric" ) {
      numericInput(temp_col()[i], label = temp_col()[i],value = 0)
    }
    else if(abc()[i] == "factor") {
      selectInput(temp_col()[i], label = temp_col()[i],choices = unique(model()$model[i]))
    }
  })

  shiny::tagList(
    shiny::fluidRow(
      # odd cols column
      shiny::column(6, inputs_temp[1:length(inputs_temp) %% 2 != 0]),
      # even cols column
      shiny::column(6, inputs_temp[1:length(inputs_temp) %% 2 == 0])
    )
  )
}

But note that you didn't provide a reproducible example, so I couldn't test the accuracy of the answer. If you edit the question with an small working example of your app, I can tweak and edit my answer to work with it.

MalditoBarbudo
  • 1,815
  • 12
  • 18
  • Working fine, Thanks – Pallav Gupta Nov 25 '19 at 10:25
  • But it is taking column from the Right side of page, Can it be dome from left – Pallav Gupta Nov 25 '19 at 10:35
  • Please, edit your question with a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) of your app, at least a minimal example working. If not, there is nothing more I can do as I can't test what is your problem. – MalditoBarbudo Nov 25 '19 at 10:43