简体   繁体   中英

ui.R returning check-box data to server.R, but how to convert “closure” to vector in the server.R file?

My ui.R file has the following that allows the user to select checkboxes. When I try making sense of it in my server.R file through:

a <- renderText({ print(input$checkGroup) })
df <- df %>% filter(match(mfr, a)) %>% select(df)

I get the following error:

Error in filter_impl(.data, dots) : 'match' requires vector arguments

I tried looking on StackOverflow for an answer and someone suggested using the cat operator, but when I do so, I get

argument 1 (type 'closure') cannot be handled by 'cat'

fluidPage(
  checkboxGroupInput('checkGroup', label = h3("Checkbox group"), 
  choiceNames = list(...),
                 choiceValues = list('N', 'A', 'G', 'K', 'P', 'Q', 'R'),
                 selected = 'N'),
  hr(),
  fluidRow(column(3, verbatimTextOutput("value"))) 
)),

Edit- Hey there and thanks for your comment! In my plot, I have the following bit of code:

<code> x = df[[input$nutri]], </code>

How do I modify this to use df()? If I use df(), I get the following error:

filter condition does not evaluate to a logical vector

I tried changing it out to

<code>    r_df <- reactive({df %>% filter(mfr %in% r_a()) %>% select(df)}) </code>

but I get

All select() inputs must resolve to integer column positions. The following do not: * df

As a headsup- I'm checking if the vector r_a has an element that equals a value in the df.

Use reactives:

r_a <- reactive(input$checkGroup)
r_df <- reactive({df %>% filter(match(mfr, r_a())) %>% select(df)})

then use r_df() in the renderPlot

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM