It seems that there is an error in the initial example code on the website https://shiny.posit.co, where it is required to add the sidebar parameter.
original code:
ui <- page_fillable(theme = bs_theme(bootswatch = "minty"),
layout_sidebar(fillable = TRUE,
sidebar(
varSelectInput("xvar", "X variable", df_num, selected = "Bill Length (mm)"),
varSelectInput("yvar", "Y variable", df_num, selected = "Bill Depth (mm)"),
checkboxGroupInput("species", "Filter by species",
choices = unique(df$Species), selected = unique(df$Species)
),
hr(), # Add a horizontal rule
checkboxInput("by_species", "Show species", TRUE),
checkboxInput("show_margins", "Show marginal plots", TRUE),
checkboxInput("smooth", "Add smoother"),
),
plotOutput("scatter")
)
code fixed
ui <- page_fillable(theme = bs_theme(bootswatch = "minty"),
layout_sidebar(fillable = TRUE,
sidebar = sidebar(
varSelectInput("xvar", "X variable", df_num, selected = "Bill Length (mm)"),
varSelectInput("yvar", "Y variable", df_num, selected = "Bill Depth (mm)"),
checkboxGroupInput("species", "Filter by species",
choices = unique(df$Species), selected = unique(df$Species)
),
hr(), # Add a horizontal rule
checkboxInput("by_species", "Show species", TRUE),
checkboxInput("show_margins", "Show marginal plots", TRUE),
checkboxInput("smooth", "Add smoother"),
),
plotOutput("scatter")
)
)
In the code, we can see that if the parameter name is not specified, it is assumed to represent the body of the dashboard and not the Sidebar.
#' @rdname sidebar
#' @param sidebar A [sidebar()] object.
#' @param fillable Whether or not the main
content area should be considered a
#' fillable (i.e., flexbox) container.
#' @param fill Whether or not to allow the layout container to grow/shrink to fit a
#' fillable container with an opinionated height (e.g., page_fillable()
).
#' @param border Whether or not to add a border.
#' @param border_radius Whether or not to add a border radius.
#' @param border_color The border color that is applied to the entire layout (if
#' border = TRUE
) and the color of the border between the sidebar and the
#' main content area.
#' @inheritParams card
#' @inheritParams page_fillable
#'
#' @export
layout_sidebar <- function(
...,
sidebar = NULL,
fillable = TRUE,
fill = TRUE,
bg = NULL,
fg = NULL,
border = NULL,
border_radius = NULL,
border_color = NULL,
padding = NULL,
gap = NULL,
height = NULL
)