Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 204798

Putting widgets in multiple columns in shiny

$
0
0

I have an excel workbook with multiple tabs, in this case 3, which looks like this: Tab1,Tab2,Tab3.

My code is this:

library(shiny)
library(readxl)
library(tidyverse)

ui <- fluidPage(
  fileInput("config","Load Configuration File",accept =c('.xls',',xlsx')),
  actionButton("show_fields","Show Fields"),
  uiOutput("ui"),
)
server <- function(input,output) {

  read_excel_allsheets <- function(filename, tibble = FALSE) {
    sheets <- readxl::excel_sheets(filename)
    x <- lapply(sheets, function(X) readxl::read_excel(filename, sheet = X))
    if(!tibble) x <- lapply(x, as.data.frame)
    names(x) <- sheets
    return(x)
  }
  sheets <- reactive({read_excel_allsheets(input$config$datapath)})
  design <- eventReactive(input$show_fields, {
    fluidPage(
      numericInput("size","Size",value = 0),
       lapply(names(sheets()), function(sheet) {
        conf <- eval(parse(text = paste("sheets()$",sheet))) %>% column_to_rownames(., var = "Rows")
        lapply(1:nrow(conf),function(i) {
          selectInput(row.names(conf)[i],label = row.names(conf)[i],choices = colnames(conf))
        })
      })
    )
  })
  output$ui <- renderUI({design()})

 }

shinyApp(ui=ui,server = server)

Running this code will look like this: UI,

Upload the excel workbook with multiple tabs, click 'show fields' button, it will show all the values in Column 1 as Dropdown names and Rest of the column names as respective choices.

I want to put all dropdowns(selectInputs) and one numericInput named as Size in multiple(2 or 3) columns. Thanks in advance.


Viewing all articles
Browse latest Browse all 204798

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>