-
DescriptionI am using Quarto version 1.5.56 on Mac and Windows. ---
title: "Not Cars Plot Explorer"
author: "Your Name"
format: dashboard
server: shiny
---
```{r}
#| context: setup
library(ggplot2)
library(plotly)
library(shiny)
# Create a small example dataset
dados <- data.frame(
Year = rep(2004:2010, 3),
Value = c(50, 60, 55, 70, 75, 80, 85,
20, 30, 40, 50, 45, 55, 65,
90, 85, 80, 75, 65, 60, 50),
Category = rep(c("A", "B", "C"), each = 7)
)
# Sample dataset
dataset <- dados
```
# {.sidebar}
```{r}
# Dropdown menu to choose between Raw Plot and Smoothed Plot
selectInput('plot_type', 'Select Plot Type:',
choices = c("Raw Plot", "Smoothed Plot"))
```
# Plot
```{r}
plotlyOutput('plot')
```
# Data
```{r}
tableOutput('data')
```
```{r}
#| context: server
# Reactive function to return the dataset
dataset <- reactive({
dados
})
# Render the plot based on user selection
output$plot <- renderPlotly({
# Base plot
p <- ggplot(dataset(), aes(
x = Year,
y = Value,
color = Category,
group = Category
)) +
geom_line() +
geom_point() +
labs(title = "Multi-Line Chart", x = "Year", y = "No.") +
theme_minimal()
# Conditionally add smoothing based on user input
if (input$plot_type == "Smoothed Plot") {
p <- ggplot(dataset(), aes(
x = Year,
y = Value,
color = Category,
group = Category
)) +
geom_smooth(method = "loess", se = FALSE) + # Apply loess smoothing
labs(title = "Multi-Line Chart with Loess Smoothing", x = "Year", y = "No.") +
theme_minimal()
}
# Convert ggplot to plotly for interactivity
ggplotly(p)
})
# Render the data table
output$data <- renderTable({
dataset()
})
```
|
Beta Was this translation helpful? Give feedback.
Answered by
gadenbuie
Sep 10, 2024
Replies: 1 comment 2 replies
-
@gadenbuie Sorry to ping you here. I figured you might know or have some insights here. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem is in this section of the markup.
It's not clear from the markup alone, but Quarto uses the page title
# Plot
and# Data
as theid
for the page controls (noticedata-bs-target="#plot"
in the snippet for the navbar Plot button.The content associated with those buttons is later in the HTML (I've taken a lot of the content out) have
id="plot"
andid="data"
.