Error message when run the Shiny app tutorial example for Lesson 4 on

Hi all,

I am new to Shiny app. I tried to run the sample codes listed on Shiny - Display reactive output
library(shiny)

ui <- fluidPage(
titlePanel("censusVis"),

sidebarLayout(
sidebarPanel(
helpText("Create demographic maps with
information from the 2010 US Census."),

  selectInput("var", 
              label = "Choose a variable to display",
              choices = c("Percent White", 
                          "Percent Black",
                          "Percent Hispanic", 
                          "Percent Asian"),
              selected = "Percent White"),
  
  sliderInput("range", 
              label = "Range of interest:",
              min = 0, max = 100, value = c(0, 100))
),

mainPanel(
  textOutput("selected_var"),
  textOutput("min_max")
)

)
)

server <- function(input, output) {

output$selected_var <- renderText({
paste("You have selected", input$var)
})

output$min_max <- renderText({
paste("You have chosen a range that goes from",
input$range[1], "to", input$range[2])
})

}

shinyApp(ui, server)
But I got an error message of: + ui <- fluidPage(
Error: unexpected symbol in:
" )
UI"

Would you please let me know how to fix this problem?
Thanks,
Hui

The code you have here seems correct. Make sure you have exactly the same code in your RStudio editor (perhaps create a new file and paste it again). Also make sure that you use the "Run App" button on top-right of the editor to run the code.

Hi, try this perhaps. The same as on the page, but with the library at the top and in the one place:

library(shiny)

ui <- fluidPage(
  titlePanel("censusVis"),
  
  sidebarLayout(
    sidebarPanel(
      helpText("Create demographic maps with 
               information from the 2010 US Census."),
      
      selectInput("var", 
                  label = "Choose a variable to display",
                  choices = c("Percent White", 
                              "Percent Black",
                              "Percent Hispanic", 
                              "Percent Asian"),
                  selected = "Percent White"),
      
      sliderInput("range", 
                  label = "Range of interest:",
                  min = 0, max = 100, value = c(0, 100))
    ),
    
    mainPanel(
      textOutput("selected_var")
    )
  )
)

server <- function(input, output) {
  
  output$selected_var <- renderText({ 
    paste("You have selected", input$var)
  })
  
}

shinyApp(ui, server)

This topic was automatically closed 54 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.