From 2b6e18fbb94f8ead09975438ea16a3da9bcf1cd3 Mon Sep 17 00:00:00 2001 From: DivadNojnarg Date: Thu, 26 Sep 2024 21:20:47 +0200 Subject: [PATCH] tweaks --- README.Rmd | 20 +--------- README.md | 112 ++++------------------------------------------------- index.Rmd | 18 ++++++++- index.md | 105 +++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 126 insertions(+), 129 deletions(-) diff --git a/README.Rmd b/README.Rmd index d3c05aa..1aea7b6 100644 --- a/README.Rmd +++ b/README.Rmd @@ -24,22 +24,4 @@ pak::paks("RinteRface/shiny386") ## Example -shiny366 demo image - -

- -Toggle code - -

- -
-```{r, results="asis", echo=FALSE, warning=FALSE, comment = ""} -shiny386:::print_r_code("penguins") -``` -
\ No newline at end of file +shiny366 demo image \ No newline at end of file diff --git a/README.md b/README.md index d71526d..e314656 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,13 @@ # shiny386 -[![CRAN status](https://www.r-pkg.org/badges/version/shiny386)](https://CRAN.R-project.org/package=shiny386) -[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) -[![R build status](https://github.com/RinteRface/shiny386/workflows/R-CMD-check/badge.svg)](https://github.com/RinteRface/shiny386/actions) -[![R-CMD-check](https://github.com/RinteRface/shiny386/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/RinteRface/shiny386/actions/workflows/R-CMD-check.yaml) + +[![CRAN +status](https://www.r-pkg.org/badges/version/shiny386)](https://CRAN.R-project.org/package=shiny386) +[![Lifecycle: +experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) +[![R build +status](https://github.com/RinteRface/shiny386/workflows/R-CMD-check/badge.svg)](https://github.com/RinteRface/shiny386/actions) The goal of shiny386 is to provide an old school Bootstrap 4 template @@ -26,104 +29,3 @@ pak::paks("RinteRface/shiny386") ## Example shiny366 demo image - -

- Toggle code -

- -
- -``` r -library(shiny) -library(shiny386) -library(bslib) -library(dplyr) -library(ggplot2) -library(ggExtra) -library(thematic) - -thematic_shiny(font = "auto") - -penguins_csv <- "https://raw.githubusercontent.com/jcheng5/simplepenguins.R/main/penguins.csv" - -df <- readr::read_csv(penguins_csv) -# Find subset of columns that are suitable for scatter plot -df_num <- df |> select(where(is.numeric), -Year) - -ui <- page_386( - h1("Penguins App"), - br(), - - h3("This app is just amazing..."), - - fluidRow( - column( - width = 4, - card_386( - title = "Aesthetics", - status = "warning", - select_input_386("xvar", "X variable", colnames(df_num), selected = "Bill Length (mm)"), - select_input_386("yvar", "Y variable", colnames(df_num), selected = "Bill Depth (mm)"), - checkbox_group_input_386( - "species", "Filter by species", - choices = unique(df$Species), - selected = unique(df$Species) - ) - ), - card_386( - title = "Other options", - status = "warning", - checkbox_input_386("by_species", "Show species", TRUE), - checkbox_input_386("show_margins", "Show marginal plots", TRUE), - checkbox_input_386("smooth", "Add smoother") - ), - button_386("run", "Do plot!", class = "btn-lg btn-block") - ), - column( - width = 8, - jumbotron_386(plotOutput("scatter")) - ) - ) -) - -server <- function(input, output, session) { - - subsetted <- eventReactive(input$run, { - req(input$species) - df |> filter(Species %in% input$species) - }) - - output$scatter <- renderPlot( - { - p <- ggplot(subsetted(), aes(.data[[input$xvar]], .data[[input$yvar]])) + - list( - theme(legend.position = "bottom"), - if (input$by_species) aes(color = Species), - geom_point(), - if (input$smooth) geom_smooth() - ) - - if (input$show_margins) { - margin_type <- if (input$by_species) "density" else "histogram" - p <- ggExtra::ggMarginal(p, - type = margin_type, margins = "both", - size = 8, groupColour = input$by_species, groupFill = input$by_species - ) - } - - p - }, - res = 100 - ) -} - -shinyApp(ui, server) -``` - -
diff --git a/index.Rmd b/index.Rmd index eec9eb0..37b1ade 100644 --- a/index.Rmd +++ b/index.Rmd @@ -36,7 +36,23 @@ card( ) ``` -The code may be found [here](https://github.com/RinteRface/shiny386/blob/78c01d766912f9d1168e28fdd77e94bf4c93ebe1/inst/examples/shinylive/penguins/app.R). +

+ +Toggle code + +

+ +
+```{r, results="asis", echo=FALSE, warning=FALSE, comment = ""} +shiny386:::print_r_code("penguins") +``` +

diff --git a/index.md b/index.md index fc6170a..07a6eec 100644 --- a/index.md +++ b/index.md @@ -26,7 +26,7 @@ pak::pak("RinteRface/shiny386") ## Demo -
+
@@ -36,15 +36,112 @@ pak::pak("RinteRface/shiny386")
+

+ Toggle code +

+ +
-The code may be found -[here](https://github.com/RinteRface/shiny386/blob/78c01d766912f9d1168e28fdd77e94bf4c93ebe1/inst/examples/shinylive/penguins/app.R). +``` r +library(shiny) +library(shiny386) +library(bslib) +library(dplyr) +library(ggplot2) +library(ggExtra) +library(thematic) + +thematic_shiny(font = "auto") + +penguins_csv <- "https://raw.githubusercontent.com/jcheng5/simplepenguins.R/main/penguins.csv" + +df <- readr::read_csv(penguins_csv) +# Find subset of columns that are suitable for scatter plot +df_num <- df |> select(where(is.numeric), -Year) + +ui <- page_386( + h1("Penguins App"), + br(), + + h3("This app is just amazing..."), + + fluidRow( + column( + width = 4, + card_386( + title = "Aesthetics", + status = "warning", + select_input_386("xvar", "X variable", colnames(df_num), selected = "Bill Length (mm)"), + select_input_386("yvar", "Y variable", colnames(df_num), selected = "Bill Depth (mm)"), + checkbox_group_input_386( + "species", "Filter by species", + choices = unique(df$Species), + selected = unique(df$Species) + ) + ), + card_386( + title = "Other options", + status = "warning", + checkbox_input_386("by_species", "Show species", TRUE), + checkbox_input_386("show_margins", "Show marginal plots", TRUE), + checkbox_input_386("smooth", "Add smoother") + ), + button_386("run", "Do plot!", class = "btn-lg btn-block") + ), + column( + width = 8, + jumbotron_386(plotOutput("scatter")) + ) + ) +) + +server <- function(input, output, session) { + + subsetted <- eventReactive(input$run, { + req(input$species) + df |> filter(Species %in% input$species) + }) + + output$scatter <- renderPlot( + { + p <- ggplot(subsetted(), aes(.data[[input$xvar]], .data[[input$yvar]])) + + list( + theme(legend.position = "bottom"), + if (input$by_species) aes(color = Species), + geom_point(), + if (input$smooth) geom_smooth() + ) + + if (input$show_margins) { + margin_type <- if (input$by_species) "density" else "histogram" + p <- ggExtra::ggMarginal(p, + type = margin_type, margins = "both", + size = 8, groupColour = input$by_species, groupFill = input$by_species + ) + } + + p + }, + res = 100 + ) +} + +shinyApp(ui, server) +``` + +

You can play with the demo app below and modify the code. -
+