Skip to content

Commit

Permalink
Merge pull request #1 from RinteRface/shinylive
Browse files Browse the repository at this point in the history
add shinylive
  • Loading branch information
DivadNojnarg authored Sep 25, 2024
2 parents 57fab6c + a1ed22e commit be15ec8
Show file tree
Hide file tree
Showing 23 changed files with 1,298 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
^LICENSE\.md$
^.vscode$
^index\.md$
^README\.Rmd$
^index\.Rmd$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
docs
.DS_Store
inst/examples/**/rsconnect

/.quarto/
12 changes: 8 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shiny386
Title: Old School 'Bootstrap 4' Template for Shiny
Version: 0.0.0.9000
Version: 0.0.1.9000
Authors@R:
person(given = "David",
family = "Granjon",
Expand All @@ -12,12 +12,16 @@ Description: This template is made for people having nostalgic feelings about fl
Less distraction for more productivity!
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
URL: https://github.com/RinteRface/shiny386
RoxygenNote: 7.3.2
URL: https://github.com/RinteRface/shiny386, https://rinterface.github.io/shiny386
BugReports: https://github.com/RinteRface/shiny386/issues
Imports:
htmltools (>= 0.5.2),
shiny,
httpuv,
httpuv
Suggests:
bslib
Depends:
R (>= 2.10)
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# shiny386 0.0.1.9000

## Features

* Added shinylive demo to pkgdown website.

## Bug fixes

* Fix default value for `checkbox_input_386()`.

# shiny386 0.0.0.9000

* Added a `NEWS.md` file to track changes to the package.
2 changes: 1 addition & 1 deletion R/inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ update_toggle_input_386 <- function (session, inputId, label = NULL, value = NUL
#' shinyApp(ui, server)
#' }
checkbox_input_386 <- function(inputId, label, value = FALSE, width = NULL) {
create_checkbox_tag(inputId, label, value = FALSE, width = NULL, type = "checkbox")
create_checkbox_tag(inputId, label, value = value, width = NULL, type = "checkbox")
}


Expand Down
4 changes: 2 additions & 2 deletions R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ page_386 <- function(..., title = NULL) {
...
)
)
)
)
)
}



#' Create a Bootstrap 386 tabset panel
#' @inheritParams shiny::tabsetPanel
#' @param position Tabs position.
#' @param position Tabs position (left or right).
#' @export
#' @examples
#' if (interactive()) {
Expand Down
Binary file added R/sysdata.rda
Binary file not shown.
43 changes: 43 additions & 0 deletions R/utils-shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,46 @@ buildTabItem <- function (index, tabsetId, foundSelected, tabs = NULL, divTag =
}
return(list(liTag = liTag, divTag = divTag))
}

#' Create shinylive iframe
#'
#' Useful for pkgdown website
#'
#' @param url app url. A shinylive link.
#' @param mode How to display the shinylive app. Default to app mode.
#' @param header Whether to display the shinylive header. Default to TRUE.
#' @keywords internal
create_app_link <- function(url, mode = c("app", "editor"), header = TRUE) {
mode <- match.arg(mode)

if (mode != "editor") url <- gsub("editor", mode, url)

if (!header) {
url <- paste0(url, "&h=0")
}

tags$iframe(
# To allow the content to fill the full screen card
class = "html-fill-item",
src = url,
height = "700",
width = "100%",
style = "border: 1px solid rgba(0,0,0,0.175); border-radius: .375rem;",
allowfullscreen = "",
allow = "autoplay",
`data-external` = "1"
)
}

code_chunk <- function(output, language = "r") {
cat(paste0("```", language))
cat(output)
cat("\n```\n")
}

print_r_code <- function(name) {
path <- system.file(sprintf("examples/shinylive/%s/app.R", name), package = "shiny386")
lines <- readLines(path)
to_remove <- grep("webr::", lines)
code_chunk(cat(paste(lines[-to_remove], collapse = "\n")))
}
45 changes: 45 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

# shiny386

<!-- badges: start -->
[![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)
<!-- badges: end -->

The goal of shiny386 is to provide an old school Bootstrap 4 template for Shiny. It is built on top of the [Bootstrap 386](http://kristopolous.github.io/BOOTSTRA.386/demo.html) HTML template.

## Installation

You can install the released version of shiny386 from Github with:

``` r
pak::paks("RinteRface/shiny386")
```

## Example

<img src="man/figures/penguins-demo.png" alt="shiny366 demo image" width="100%">

<p class="text-center">
<a
class="btn btn-primary"
data-bs-toggle="collapse"
href="#demo-code"
role="button"
aria-expanded="false"
aria-controls="demo-code">
Toggle code
</a>
</p>

<div class="collapse" id="demo-code">
```{r, results="asis", echo=FALSE, warning=FALSE, comment = ""}
shiny386:::print_r_code("penguins")
```
</div>
108 changes: 98 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# shiny386

<!-- badges: start -->
Expand All @@ -8,34 +10,120 @@
[![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)
<!-- badges: end -->

The goal of shiny386 is to provide an old school Bootstrap 4 template for Shiny. It is built on top of the [Bootstrap 386](http://kristopolous.github.io/BOOTSTRA.386/demo.html) HTML template.
The goal of shiny386 is to provide an old school Bootstrap 4 template
for Shiny. It is built on top of the [Bootstrap
386](http://kristopolous.github.io/BOOTSTRA.386/demo.html) HTML
template.

## Installation

You can install the released version of shiny386 from Github with:

``` r
remotes::install_github("RinteRface/shiny386")
pak::paks("RinteRface/shiny386")
```

## Example

This is a basic example which shows you how to solve a common problem:
<img src="man/figures/penguins-demo.png" alt="shiny366 demo image" width="100%">

<p class="text-center">
<a
class="btn btn-primary"
data-bs-toggle="collapse"
href="#demo-code"
role="button"
aria-expanded="false"
aria-controls="demo-code"> Toggle code </a>
</p>

<div id="demo-code" class="collapse">

``` 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(
card_386(
title = "My card",
"This is my card",
h1("Penguins App"),
br(),
card_link_386(href = "https://www.google.com", "More"),
footer = "Card footer"
)

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) {}
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)
```

</div>
3 changes: 3 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
template:
bootstrap: 5
url: https://rinterface.github.io/shiny386/
3 changes: 1 addition & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## Test environments
* local R installation, R 3.6.1
* ubuntu 16.04 (on travis-ci), R 3.6.1
* local R installation, R 4.2.2
* win-builder (devel)

## R CMD check results
Expand Down
Loading

0 comments on commit be15ec8

Please sign in to comment.