0

I'm building my first shiny app and I've run into a little difficulty which i cant understand

My code wants to take the input from the user - add one then print the output please ignore the radio buttons for now -

    ui <- shinyUI(fluidPage(

  titlePanel("alpha"),

    sidebarPanel(numericInput("expn", 
                              "Please enter total number of reports received", 1,
                              min = 0,
                              max = 1000000
    ),
     radioButtons(inputId = "'QC_Type'", label = "QC Type", 
                 choices = c("Overall", "Solicited", "Spontaneous", 
                             "Clinical Trial","Literature" ),


    mainPanel(
      textOutput("results"))

    ))))





  server <- function (input, output) {
    output$results <- renderText(
    { print(1 +(Input$expn))
  }
  )
}

shinyApp(ui = ui, server = server)

I'm unable to see any output when I run the code.

Thank you for your time :)

1 Answer 1

2

That's because of where your mainPanelis located. It should follow the sidebarPanel. Also, I recommend using as.character() instead of print(), unless you really want to print out the output on the console.

Here's the corrected code:

ui <- shinyUI(fluidPage(
  titlePanel("alpha"),

  sidebarPanel(
    numericInput(
      "expn",
      "Please enter total number of reports received",
      1,
      min = 0,
      max = 1000000
    ),
    radioButtons(
      inputId = "'QC_Type'",
      label = "QC Type",
      choices = c(
        "Overall",
        "Solicited",
        "Spontaneous",
        "Clinical Trial",
        "Literature"
      )
    )
  ),
  mainPanel(textOutput("results"))
))

server <- function (input, output) {
  output$results <- renderText({
    as.character(1 + (input$expn))
  })
}

shinyApp(ui = ui, server = server)

I recommend using good practices when indenting code. It makes things easier to read and to find where braces and parentheses are.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.