从文件输入中渲染变量

时间:2018-04-17 08:42:06

标签: r shiny

我正在尝试开发一个应用程序,我在其中设计了包含两个菜单子项的仪表板。

  1. 加载
  2. 制备
  3. 在加载中,我使用文件输入,允许用户上传文件。

    2.在准备中,我想以checkgroupbox的形式显示文件中的标题。

    为此,我尝试了以下代码。在下面的代码中,我有以下问题。 1.在Prep中我需要的变量选择在Load中可用。

    1. 选择变量,我想在复选框中显示它们,以便用户可以选择他们想要的变量。
    2. 这是我的代码,任何人都可以帮助我如何实现它吗?

      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)
      

0 个答案:

没有答案
相关问题