代码之家  ›  专栏  ›  技术社区  ›  logisticregress

R/闪亮数据框列

  •  0
  • logisticregress  · 技术社区  · 7 年前

    我正在和Shining合作,我还有一个问题,希望更简单:

    我有一个数据帧(从csv上传),我想让用户选择一个因变量,然后选择他们的自变量,但是用于IV选择的可用列列表现在不应该包括他们刚刚选择的因变量。

    我一整天都在盯着和反应性的表情,毫无头绪。这可能也很明显。 任何帮助都会很好。

    这是服务器代码中的代码段

    # Read file ----
    df <- reactive({
     req(input$uploaded_file)
     read.csv(input$uploaded_file$datapath,
             header = input$header,
             sep = input$sep)  
    
     })
    
    
    # dynamically allow the user to select a dependent variable ----
      output$selectbox <- renderUI({
      selectInput(inputId = "select_dev", 
                label = "Select target variable", 
                choices = names(df()))
    })
    
    # Dynamically allow the user to select their independent variables using checkboxes ----
    ###
    ###  Here is where I would like to remove the variable from the DF that they selected in output$selectbox. 
    ###
      output$checkbox <- renderUI({
      checkboxGroupInput(inputId = "select_var", 
                       label = "Select variables", 
                       choices = names(df()),
                       selected = names(df()))
    })
    

    也许有一种比这更容易操作反应函数的方法。目标是让数据框架成为一组独立变量,并能够调用它进行多个分析。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Shree    7 年前

    你去了——

    library(shiny)
    
    shinyApp(
      ui = fluidPage(
        uiOutput("selectbox"),
        uiOutput("checkbox")
      ),
      server = function(input, output, session) {
    
        df <- reactive(iris)
    
        output$selectbox <- renderUI({
          selectInput(inputId = "select_dev", 
                      label = "Select target variable", 
                      choices = names(df()))
        })
    
        output$checkbox <- renderUI({
          checkboxGroupInput(inputId = "select_var", 
                             label = "Select variables", 
                             choices = setdiff(names(df()), input$select_dev),
                             selected = setdiff(names(df()), input$select_dev))
        })
      }
    )
    
    推荐文章