[英]R/Shiny Dataframe Columns
I'm working with Shiny, and i have another question, hopefully much easier: 我正在与Shiny合作,但我还有另一个问题,希望可以轻松得多:
I have a dataframe (uploaded from a CSV), where I want the user to select a Dependent variable, and then select their independent variables, but the list of available columns for the IV selection should now not include the dependent variable that they just selected. 我有一个数据框(从CSV上载),我希望用户选择一个因变量,然后选择其自变量,但是IV选择的可用列列表现在不应包括他们刚刚选择的因变量。
I've been staring and reactive expressions all day, and have no clue. 我整天都在凝视着反应性的表情,毫无头绪。 It's probably really obvious too.
这也可能真的很明显。 Any help would be great.
任何帮助都会很棒。
Here is a code snippet from the Server code 这是服务器代码中的代码片段
# 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()))
})
Perhaps there is an easier way than this to manipulate a reactive function. 也许有比这更简单的方法来操纵反应函数。 The goal is to have dataframe that I can treat as a set of independent variables, and be able to call on it for multiple analyses.
我们的目标是拥有一个数据框,我可以将其视为一组独立变量,并可以对其进行多次分析。
There you go - 你去了-
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.