I have made an shiny app where I am giving a fileInput where user can input an excel sheet 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"),
actionButton("estimate","Estimate"),
uiOutput("ui"),
textOutput("prod")
)
server <- function(input,output) {
x <- reactive({read_excel(input$config$datapath)})
conf <- reactive({x() %>% column_to_rownames(., var = "Rows")})
design <- eventReactive(input$show_fields, {
fluidPage(
numericInput("size","Size",value = 0),
lapply(1:nrow(conf()),function(i) {
selectInput(row.names(conf())[i],label = row.names(conf())[i],choices = colnames(conf()))
})
)
})
output$ui <- renderUI({design()})
mul <- eventReactive(input$estimate, {
sapply(1:nrow(conf()), function(j) {
conf()[row.names(conf())[j],eval(parse(text = paste0("input$",row.names(conf())[j],sep = "")))]
})
})
output$prod <- renderText({paste("Product is: ",prod(mul(),na.rm = TRUE)*input$size)})
}
shinyApp(ui=ui,server = server)
when loading the xls sheet, 'Show Fields' button will show all the Rows as Drop-downs with columns as choices. So at last whatever I choose upon clicking 'Estimate' button Product will be shown of all corresponding values from excel sheet and the inputed size.
But this code is only working if I don't have different features (like U, V, W,K,L etc). You can run this code by removing rows from row 7 onwards.
So now what I want:
1: All the boxes (numericInput & selectInputs) shall come in two or three columns. The page shall look filled.
2: I want same things to happen with the actual sheet.
Here A-E,U-Z,K-O are drop-downs choices, for corresponding rows(like A-Z for Ram, Shyam etc. , U-Z for Predeep, Sudeep and K-O for Aneeta). I want each such dropdowns and whatever user selects I need to provide the product of all corresponding values from excel sheet along with given Size.
I am trying this out for many days now, and now I am frustated. Somebody please do it.