Reputation: 35
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 :)
Upvotes: 0
Views: 58
Reputation: 256
That's because of where your mainPanel
is 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.
Upvotes: 2