I have an excel workbook with multiple tabs, in this case 3, which looks like this:
,
,
.
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:
,
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.