R Shiny - New Data Frame

I was wondering if some-one can help with the following.
I've just started using R Shiny and I wanted to create a data frame and then a bar chart
I have been trying to code the following in the server.R but can't get it to work.

Create new Data Frame with 2 variables, "cat" and "val"
'A' 55
'B' 90

Plot is a barchart showing x=cat, y=val

Once I can do the following I will be able to apply the dynamic variables so the plot is interchangeable.

Any help would be great.

Many Thanks.

Hi @bbb32

I think the following code will do what you are hoping. Let me know if I've misinterpreted your question.


ui <- fluidPage(
  numericInput('A', label = 'A', value = 55),
  numericInput('B', label = 'B', value = 90)),

server <- function(input, output, session){

  output$barplot <- renderPlot({
    data <- data.frame(cat = c('A', 'B'),
                       val = c(input$A, input$B))
    barplot(data$val, names.arg = data$cat)

shinyApp(ui, server)

Hi @mattwarkentin,

Thanks for your response much appreciated.

My problem is the numericInput is going to be dynamic variables that are created from the other numericInputs I have


numericInput: a = 10
numericInput: b = 55

Want to create a new variable c = a + b and report c in the barplot


Hi @bbb32

I understand now. In theory it is not difficult to have two inputs be combined to form a third variable. However, what amount of flexibility do you want? Do you want the number of inputs to vary? Do you want to control which inputs get combined?

Hi @mattwarkentin,
The plan is to have the same number of inputs and then use different combination of the inputs (which will not change) to provide outputs.

Input1: A=25
Input2: b=30
Input3: c=22
Input4: d=32

T1 = A + C

T2 = A + B

T3 = B +C

Plot of T1, T2, T3 [on the same plot]


@mattwarkentin got it working.
Thanks so much for your help.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.