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

Support `nav_panel` within apps using the `page_navbar` template #190

Closed rpodcast closed 8 months ago

rpodcast commented 9 months ago

After creating a simple app in the editor based on the navbar template (which had no issues), I decided to try loading a pre-made app based on this example with a few modifications. In my adapted example, I'm using nav_panel instead of tabPanel which is used in the fresh template. Would it be possible to have nav_panel supported? I know it's not trivial to add support for additional UI elements coming from separate packages, but this would be a great value to future uses of the editor with bslib- powered dashboards.

Example application

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

# install.packages("palmerpenguins")
data(penguins, package = "palmerpenguins")

ui <- page_navbar(
  title = "Penguins dashboard",
  sidebar = selectInput(
    selected = "species",
    inputId = "color_by",
    label = "Color by",
    choices = c(
      "species",
      "island",
      "sex"
    )
  ),
  collapsible = nav_spacer(),
  nav_panel(
        "Bill Length", 
        card(
          full_screen = TRUE,
          card_header("Bill Length"),
          plotOutput("bill_length")
        )
      ),
  nav_panel(
        "Bill Depth", 
        card(
          full_screen = TRUE,
          card_header("Bill depth"),
          plotOutput("bill_depth")
        )
      ),
  nav_panel(
        "Body Mass", 
        card(
          full_screen = TRUE,
          card_header("Body Mass"),
          plotOutput("body_mass")
        )
      ),
  nav_item(tags$a("Posit", href = "https://posit.co"))
)

server <- function(input, output) {
  gg_plot <- reactive({
    ggplot(penguins) +
      geom_density(aes(fill = !!input$color_by), alpha = 0.2) +
      theme_bw(base_size = 16) +
      theme(axis.title = element_blank())
  })

  output$bill_length <- renderPlot(gg_plot() + aes(bill_length_mm))
  output$bill_depth <- renderPlot(gg_plot() + aes(bill_depth_mm))
  output$body_mass <- renderPlot(gg_plot() + aes(body_mass_g))
}

shinyApp(ui, server)
nstrayer commented 9 months ago

Absolutely, nav_panel() should be supported. Putting this into the queue of next steps.

nstrayer commented 9 months ago

As of #215, most of that example app will work. There are a few areas where the UI editor still gets tripped up.

  1. It wants to the sidebar wrapped in a sidebar call. This can/ probably should be updated. #217
  2. It doesn't know how to deal with collapsible = nav_spacer().
  3. nav_item() isn't supported. #216