input dynamic radio buttons, shiny app R

hi guys,
I'm creating an app with shiny in R, I'm curious how to insert dynamically the inputs of radio button with the names of column of the datasets that i uploaded.

This is my code, but it returned wrong items...

# app-egonetwork.R
library(shiny)

#UI Design
ui <- fluidPage(
  titlePanel(tags$strong("EgoNetwork v1.0")),
  
  sidebarLayout(
    sidebarPanel(
    
      # File Import
      fileInput(inputId="files",
                label="Import CSV File",
                accept=c("text/csv", "text/comma-separated-values", 
                         "text/plain"),
                multiple = TRUE,
                placeholder = "No files uploaded"),
      
      tags$hr(),
      checkboxInput("header", "Header", TRUE),
      
      # Theory: Show this only when file has been imported
      #
      # Practice: Not shown when file has been uploaded
      conditionalPanel(
        condition="output.files_ready",
        wellPanel(              
                   radioButtons(inputId="typeofnet", "Network based on", uiOutput("settings")),
                   radioButtons(inputId="typeofarch", "Weight of Arched based on", uiOutput("settingsArch"))
        )
      )
    ),
    mainPanel(
      tableOutput("contents")
    )
  )
)

#Server Design
server <- function(input, output) {
  
  output$contents <- renderTable({
    req(input$files)
    upload = list()
    
    for(nr in 1:length(input$files[, 1])){
      upload[[nr]] <- head(read.csv(
        file = input$files[[nr, 'datapath']]
      ))
    }
    
    return(upload)
  })
  
  output$settings <- renderText({
    return(colnames(input$files))
  })
  
  output$settingsArch <- renderText({
    req(input$files)
    upload = list()
    
    for(nr in 1:length(input$files[, 1])){
      upload[[nr]] <- colnames(read.csv(
        file = input$files[[nr, 'datapath']]
      ))
    }
    
    return(upload)
  })
  
  # Has a file been imported?
  output$files_ready <- reactive({
    return(!is.null(input$files))
  })
  
  # activate the output so it runs although not displayed
  outputOptions(output, "files_ready", suspendWhenHidden = FALSE)
  
}

#Runapp
shinyApp(ui = ui, server = server)

this is the result....

This topic was automatically closed 21 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.