Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Sep 25, 2024
1 parent 78c01d7 commit d863281
Show file tree
Hide file tree
Showing 36 changed files with 403 additions and 826 deletions.
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/
7 changes: 3 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 @@ -14,13 +14,12 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1.9000
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,
shiny,
magrittr,
httpuv
Depends:
R (>= 2.10)
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(badge_386)
export(button_386)
export(card_386)
Expand Down Expand Up @@ -47,4 +46,3 @@ export(validate_progress_value)
export(validate_status)
import(htmltools)
import(shiny)
importFrom(magrittr,"%>%")
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
2 changes: 1 addition & 1 deletion R/shiny386-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#' @import htmltools
#' @import shiny
#' @docType package
NULL
"_PACKAGE"
Binary file modified R/sysdata.rda
Binary file not shown.
11 changes: 0 additions & 11 deletions R/utils-pipe.R

This file was deleted.

46 changes: 38 additions & 8 deletions R/utils-shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,45 @@ buildTabItem <- function (index, tabsetId, foundSelected, tabs = NULL, divTag =
return(list(liTag = liTag, divTag = divTag))
}

create_link_iframe <- function(link) {
shiny::tags$iframe(
#' 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 = link,
height = "800",
width = "100%",
style = "border: 1px solid rgba(0,0,0,0.175); border-radius: .375rem;",
allowfullscreen = "",
allow = "autoplay",
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")))
}
35 changes: 18 additions & 17 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ pak::paks("RinteRface/shiny386")

## Example

This is a basic example which shows you how to solve a common problem:

``` r
library(shiny)
library(shiny386)
ui <- page_386(
card_386(
title = "My card",
"This is my card",
br(),
card_link_386(href = "https://www.google.com", "More"),
footer = "Card footer"
)
)

server <- function(input, output, session) {}
shinyApp(ui, server)
<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>
100 changes: 92 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,105 @@ 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>
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
template:
bootstrap: 5
url: https://shiny386.rinterface.com/
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
18 changes: 15 additions & 3 deletions index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,27 @@ pak::pak("RinteRface/shiny386")

## Demo

```{r showcase-code, eval=TRUE, echo=FALSE}
```{r penguins-code, eval=TRUE, echo=FALSE}
card(
shiny386:::create_link_iframe(shiny386:::shinylive_links["inst/examples/shinylive/basic"]),
shiny386:::create_app_link(shiny386:::shinylive_links["inst/examples/shinylive/penguins"], header = FALSE),
full_screen = TRUE,
style = "margin: 0 auto; float: none;"
)
```

The original app may be found [here](https://shiny.rstudio.com/gallery/bus-dashboard.html)
The code may be found [here](https://github.com/RinteRface/shiny386/blob/78c01d766912f9d1168e28fdd77e94bf4c93ebe1/inst/examples/shinylive/penguins/app.R).

<br/>

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

```{r basic-code, eval=TRUE, echo=FALSE}
card(
shiny386:::create_app_link(shiny386:::shinylive_links["inst/examples/shinylive/basic"], mode = "editor"),
full_screen = TRUE,
style = "margin: 0 auto; float: none;"
)
```

## Example

Expand Down
Loading

0 comments on commit d863281

Please sign in to comment.