0

I am trying to develop an application, where I have designed my dashboard with two menu sub items.

  1. Load
  2. Prep

In Load, I am using File input, to allow the user to upload the file.

2 .In prep, I want to display the headers from the file in the form of checkgroupbox.

For that, I have tried the below code. In the below code, I have following problems. 1. The selection of variables, I need in Prep, is available in Load.

  1. Select variables, I want to display them in checkbox, so the user can select the variables they want.

Here is my code, Could anyone help me how I could achieve it?

ui<-dashboardPage(
  dashboardHeader(title = "Model"),
  dashboardSidebar(
    sidebarMenu(id="tabs",
                menuItem("Data", tabName = "data", icon = icon("table"),startExpanded = TRUE,
                         menuSubItem("Load", tabName = "data1"),
                         menuSubItem("Prep", tabName = "prep")
                ),
                menuItem("Visualisation",icon=icon("bar-chart-o"), tabName = "vis"),
                menuItem("Result", icon=icon("cog"), tabName = "result")
    )
  ),
  dashboardBody(
    tags$style(type="text/css",
               ".shiny-output-error { visibility: hidden; }",
               ".shiny-output-error:before { visibility: hidden; }"
    ),
    tabItems(
      tabItem(tabName = "data1",
              fluidPage(
                fluidRow(
                  fileInput("file1","Choose CSV File",
                            accept = c("text/csv",
                                       "text/comma-seperated-values, text/plain",
                                       ".csv")
                  ),
                  tags$hr(),
                  checkboxInput("header", "Header", TRUE),
                  radioButtons("sep","Separator",
                               choices=c(Comma=",",
                                         semicolon=";",
                                         Tab="\t"),
                               selected = ";")
                ),
                mainPanel(
                  uiOutput("tb")
                )
              )
      )
    ),
    tabItem(tabName = "prep",
            fluidPage(
              fluidRow(
                h5("Select Varibales")
              ),
                 mainPanel(
                   uiOutput("Pre")

              )
            ))
  )
) 


server <- shinyServer(function(input,output){
  data <- reactive({
    file1 <- input$file1
    if(is.null(file1)){return()}
    read.csv(file = file1$datapath, sep=input$sep)
  })

  output$filedf <- renderTable({
    if(is.null(data())){return()}
    input$file1
  })
  output$sum <- renderTable({
    if(is.null(data())){return()}
    summary(data())
  })
  output$table <- renderTable({
    if(is.null(data())){return()}
    data()
  })
  output$tb <- renderUI({
    if(is.null(data())){return()}
    tabsetPanel(tabPanel("About file", tableOutput("filedf")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum")))

  })

                #----- Data Preparation------
 output$Pre <- renderUI({checkboxGroupInput(inputId = "select_vars",
                                            label="Select Variables",
                                            choices = names(data))

   })
data_sel <- reactive({
  req(input$select_vars)
  data_sel<- data()%>% select(input$select_var)
})
})

shinyApp(ui,server)
Mikz
  • 571
  • 2
  • 11
  • 29
  • 1
    `names(data)` must read `names(data())`, because it is a function (this is a little bit different in shiny compared to usual R). – hplieninger Apr 17 '18 at 13:58
  • @hplieninger still I could not achieve the result I want – Mikz Apr 18 '18 at 07:59
  • 1
    Have a look at [this](https://stackoverflow.com/questions/32847743/switching-between-menusubitems-in-shinydashboard). It will help you to switch between sub-menu items. – SBista Apr 18 '18 at 11:41

0 Answers0