rstudio / shinyuieditor

A GUI for laying out a Shiny application that generates clean and human-readable UI code
https://rstudio.github.io/shinyuieditor/
MIT License
209 stars 29 forks source link

nav_panel() function could not be found #240

Closed JasonDude16 closed 8 months ago

JasonDude16 commented 8 months ago

I used the tabset template and didn't make any modifications.

library(shiny)
library(ggplot2)
library(bslib)
library(gridlayout)

ui <- page_navbar(
  title = "Chick Weights",
  selected = "Line Plots",
  collapsible = TRUE,
  theme = bslib::bs_theme(),
  nav_panel(
    title = "Line Plots",
    grid_container(
      row_sizes = c(
        "1fr"
      ),
      col_sizes = c(
        "250px",
        "1fr"
      ),
      gap_size = "10px",
      layout = c(
        "num_chicks linePlots"
      ),
      grid_card(
        area = "num_chicks",
        card_header("Settings"),
        card_body(
          sliderInput(
            inputId = "numChicks",
            label = "Number of chicks",
            min = 1,
            max = 15,
            value = 5,
            step = 1,
            width = "100%"
          )
        )
      ),
      grid_card_plot(area = "linePlots")
    )
  ),
  nav_panel(
    title = "Distributions",
    grid_container(
      row_sizes = c(
        "165px",
        "1fr"
      ),
      col_sizes = c(
        "1fr"
      ),
      gap_size = "10px",
      layout = c(
        "facetOption",
        "dists"
      ),
      grid_card_plot(area = "dists"),
      grid_card(
        area = "facetOption",
        card_header("Distribution Plot Options"),
        card_body(
          radioButtons(
            inputId = "distFacet",
            label = "Facet distribution by",
            choices = list("Diet Option" = "Diet", "Measure Time" = "Time")
          )
        )
      )
    )
  )
)

server <- function(input, output) {

  output$linePlots <- renderPlot({
    obs_to_include <- as.integer(ChickWeight$Chick) <= input$numChicks
    chicks <- ChickWeight[obs_to_include, ]

    ggplot(
      chicks,
      aes(
        x = Time,
        y = weight,
        group = Chick
      )
    ) +
      geom_line(alpha = 0.5) +
      ggtitle("Chick weights over time")
  })

  output$dists <- renderPlot({
    ggplot(
      ChickWeight,
      aes(x = weight)
    ) +
      facet_wrap(input$distFacet) +
      geom_density(fill = "#fa551b", color = "#ee6331") +
      ggtitle("Distribution of weights by diet")
  })

}

shinyApp(ui, server)

Output:

Loading required package: shiny
Learn more about the underlying theory at https://ggplot2-book.org/

Attaching package: ‘bslib’

The following object is masked from ‘package:utils’:

    page

Error in nav_panel(title = "Line Plots", grid_container(row_sizes = c("1fr"),  : 
  could not find function "nav_panel"

Using: shiny 1.7.2, shinyuieditor 0.5.1

gadenbuie commented 8 months ago

Hi @JasonDude16, it seems like you may have an older version of bslib installed, since nav_panel() was introduced in bslib v0.5.0 (released 2023-06-09). You can either update to the latest version of bslib or you could try replacing all nav_panel() calls with nav() calls if you need to stay on the older version of bslib.

JasonDude16 commented 8 months ago

@gadenbuie whoops, I assumed nav_panel() would be from the shiny package. Thanks for the quick response.