简体   繁体   中英

numericInput to data frame in Shiny

Sorry if this question has been asked before, but I haven't quite found exactly what I was looking for by searching around.

I'm working on a small app to bring in scores from a debate activity and have those scores plotted in a scatterplot. I've figured out how to actually make the plot, but getting the data into it is a separate story. I have all of my inputs as a numericInput with a unique input ID, but I haven't had any luck putting that data into its own frame.

I tried making a few different sets and then compiling all of those into one frame (using name1<-c(x, yz) , name2<-c(a,b,c) ... and then frame<-as.matrix(c(name1,name2....)) but it tells me that I'm attempting to do something that requires a reactive context.

If anyone knows how I could make my numericInputs drop into a dataframe, that would be lovely.

EDIT: I think I'm looking to make a reactive data table, but I'm not entirely sure. Again, any suggestions will be greatly appreciated!

Given the description of your problem, which is not that clear and do not show exactly what you need, this is what I recomment:

An app which takes 6 numerics inputs, combine all in a data frame with two columns and create a scatter plot with that data.

library(shiny)
library(ggplot2)
library(dplyr)

# 1 - The UI with a sidebar layuot
ui <- fluidPage(
  sidebarLayout(
    # A well panell to separate the values
    # for the X axis
    sidebarPanel = sidebarPanel(
      wellPanel(
      h3("X axis"),
      numericInput('numb1', 'A', value = 1),
      numericInput('numb2', 'B', value = 2),
      numericInput('numb3', 'C', value = 3)
    ),
    # A well panell to separate the values
    # for the Y axis
    wellPanel(
      h3("Y axis"),
      numericInput('numb4', 'A', value = 1),
      numericInput('numb5', 'B', value = 2),
      numericInput('numb6', 'C', value = 3)
    )),
    
    # Main panel with the plot
    mainPanel = mainPanel(
      plotOutput("plot")
    )
  )
  
  
)

server <- function(input, output, session) {
  
  # Here You create a reactive objece with all the values
  data <- reactive({
    data.frame(
      a = c(input$numb1, input$numb2, input$numb3),
      b = c(input$numb4, input$numb5, input$numb6)
    )
  })
  
  # plot output
  output$plot <- renderPlot({
     data() %>%
      ggplot(aes(x = a, y = b)) +
      geom_point()
  })
}

shinyApp(ui, server)

Let me know if this is it

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