Table Output problem

Hello everyone, i'm trying to create my first ShinyApp and as expected i'm facing a lot of problems but most of them are quite simple.

The function of the App is basically receive a bunch of values of different variables, transform some of them, and then print a table with the original variables and the transformed ones.

The ideia is to do more things, but as they say: one step at a time

So, here follow the code, i already try a lot of different types of functions related to print table as an output but nothing is working

library(shiny)

ui <- fluidPage(
  h1("Multi-simulator test"),
  numericInput("age","Age",18,min=18,max=90),
  verbatimTextOutput("value"),
  numericInput("dlage","Drive-license Age",1,min=1,max=80),
  verbatimTextOutput("value"),
  numericInput("pp","Power rate (Horsepower/Gross-Weight)",0.1,min=0.1,max=10),
  verbatimTextOutput("value"),
  numericInput("cc","Cilinders",1,min=1,max=10000),
  verbatimTextOutput("value"),
  numericInput("kids","Have kids? (yes=1,no=0)",0,min=0,max=1),
  verbatimTextOutput("value"),
  numericInput("car_year","Year of the car",1950,min=1950,max=3000),
  verbatimTextOutput("value"),
  numericInput("lisbon","Live in Lisbon? (yes=1,no=0)",0,min=0,max=1),
  verbatimTextOutput("value"),
  tags$hr(),
  checkboxInput("CoA", "Company A", TRUE),
  checkboxInput("CoB", "Company B", TRUE),
  checkboxInput("CoC", "Company C", TRUE),
  mainPanel(
    
    tableOutput("table")
    
  )
)

server <- function(input, output) {
  
  # Reactive value for selected dataset ----
   input$car_age <- reactive(2019 - input$car_year)
   data <- reactive({data.frame(Age=input$age,Car_Age=input$car_age,
                                      Dl_age=input$dlage,Power_rate=input$pp,
                                      Cilinders=input$cc,Kids=input$kids,
                                      Lisbon=input$lisbon)})
  # Table of selected dataset ----
  output$table <- renderTable({
    data()
  })

}

shinyApp(ui = ui, server = server)

I hope this is what you are trying to do. The error was with verbatimTextOutput. I have just changed that for age. Also I put the car_age inside the reactive component itself.

library(shiny)

ui <- fluidPage(
  sidebarPanel(
  h1("Multi-simulator test"),
  numericInput("age","Age",18,min=18,max=90),
  verbatimTextOutput("textAge"),
  numericInput("dlage","Drive-license Age",1,min=1,max=80),
  numericInput("pp","Power rate (Horsepower/Gross-Weight)",0.1,min=0.1,max=10),
  numericInput("cc","Cilinders",1,min=1,max=10000),
  numericInput("kids","Have kids? (yes=1,no=0)",0,min=0,max=1),
  numericInput("car_year","Year of the car",1950,min=1950,max=3000),
  numericInput("lisbon","Live in Lisbon? (yes=1,no=0)",0,min=0,max=1),
  tags$hr(),
  checkboxInput("CoA", "Company A", TRUE),
  checkboxInput("CoB", "Company B", TRUE),
  checkboxInput("CoC", "Company C", TRUE)),
  mainPanel(
    
    tableOutput("table")
    
  )
)

server <- function(input, output) {
  
  # Reactive value for selected dataset ----
 # input$car_age <- reactive(2019 - input$car_year)
  data <- reactive({data.frame(Age=input$age,Car_Age=(2019 - input$car_year),
                               Dl_age=input$dlage,Power_rate=input$pp,
                               Cilinders=input$cc,Kids=input$kids,
                               Lisbon=input$lisbon)})
  # Table of selected dataset ----
  output$table <- renderTable({
    data()
  })
  
  output$textAge <- renderText({
    input$age
  })
  
}

shinyApp(ui = ui, server = server)
1 Like

Oooh guess i got it! Thank you very muc.
So, when i use the function numericInput i don't need to use VerbatimTextOutput to label the box where the value need to be filled?
Plus, in the last lines, why did you use an output just for the age?

Hope i am not bothering.

Yes if you are using numericInput then you dont need to use verbatim unless you want to print something else.
The last output was to show how verbatimOutput works.

1 Like

Here we go! Thank you very much!

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.