[英]R/Shiny Dataframe Columns
我正在與Shiny合作,但我還有另一個問題,希望可以輕松得多:
我有一個數據框(從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()))
})
也許有比這更簡單的方法來操縱反應函數。 我們的目標是擁有一個數據框,我可以將其視為一組獨立變量,並可以對其進行多次分析。
你去了-
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))
})
}
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.