Get data from uiOutput

Hello all. I'd need help for something maybe very simple for my first Shiny App.

In my UI part I have this :

#####################################################################################
body <- dashboardBody(tabsetPanel(type = "tabs",
tabPanel(title = "Repartition",
uiOutput("repartition"),
)
####################################################################################
####################################################################################
And in my servert part I have this :

output$repartition<-renderUI({
df<-df_products_upload() #the function which calls my dataset
noms<-colnames(df[,-1])
names<-noms
return(
lapply(1:length(noms), function(i){
column(4,
sliderInput(inputId = "names[i]", label = h5(noms[i]),
min = 0, max = 100000 , value = df[1,i+1], step = 1, width='100%'))
}))})
####################################################################################

With this code, the user will see several sliderbar with default values AND he will be able to change this values.

I would like to know how to get and manipulate those new values. To be more precise, I don't know how to acced to them.

Sorry for my english, I'll try to be clearer if it's necessary.

Thanks you

I made this example for you.

library(shiny)
library(purrr) # for map
library(glue) # for nice string interpolation
ui <- fluidPage(
  numericInput("num_controls_choice",
               "Choose how many controls to make",
               value = 1,
               min = 0,
               max = 10),
  uiOutput("dynamic_controls"),
  verbatimTextOutput("view_dynamic_controls")
)

server <- function(input, output, session) {
  output$dynamic_controls <- renderUI({
    ncc <- req(input$num_controls_choice)
    
    map(seq_len(ncc),
        ~{
          nm <- glue("control_{.}")
          sliderInput(inputId = nm ,
                      label = nm,
                      min = 0,
                      value = if(isTruthy(input[[nm]]))
                                 {input[[nm]]} else{0},
                     max = 10)
        })
  })

output$view_dynamic_controls <- renderPrint({
  ncc <- req(input$num_controls_choice)
  cat("num controls choice :", ncc, "\n")
  walk(
    seq_len(ncc),
    ~ cat(
      "\n", glue("control_{.}"),
      input[[glue("control_{.}")]]
    )
  )
})
}

shinyApp(ui, server)
1 Like

Hi nirgrahamuk, I have not resolve my problem yet but I'm working at it. Thanks for your answer, I'm trying to understand it now.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.