Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use paste0 with input$ in shiny

This is a follow up question to this Avoid DRY with 13 sliderInputs and 13 textInputs:

How can I shorten this code:

  sliderValues <- reactive({
    
    data.frame(
      Name = c("A",
               "B",   
               "C"),
      Value = as.character(c(input$a,
                             input$b,
                             input$c
                            )),
      stringsAsFactors = FALSE)
  })

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have tried:

  # Reactive expression to create data frame of all input values ----
  sliderValues <- reactive({
    
    data.frame(
      Name = c(LETTERS[1:3]),
      Value = paste0("input$", letters[1:3]),
      stringsAsFactors = FALSE)
  })

enter image description here

>Solution :

One option would be to use sapply or …

# Reactive expression to create data frame of all input values ----
  sliderValues <- reactive({
    
    data.frame(
      Name = c("A",
               "B",
               "C"),
      Value = as.character(sapply(letters[1:3], function(x) input[[x]])),
      stringsAsFactors = FALSE)
    
  })
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading