Skip to content

Commit

Permalink
Improve unsupported features docs (#192)
Browse files Browse the repository at this point in the history
* docs: add upload ad download buttons examples

* chore: add shinyjs to Suggests for examples to run

* fix: show only uploaded file name

* fix: don't run examples during package check

* chore: build docs

* fix: typing

* chore: build docs

* fix: missing ns

---------

Co-authored-by: Jakub Sobolewski <[email protected]>
  • Loading branch information
jakubsob and Jakub Sobolewski committed Jun 30, 2023
1 parent d3e3bb9 commit 98c27cb
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 3 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Suggests:
rmarkdown,
sass,
shiny.router,
shinyjs,
sortable,
stringi,
testthat (>= 3.0.0),
Expand Down
2 changes: 2 additions & 0 deletions R/examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ NULL

#' @example inst/examples/Button.R
#' @example inst/examples/Button2.R
#' @example inst/examples/Button3.R
#' @example inst/examples/Button4.R
#' @name Button
NULL

Expand Down
54 changes: 54 additions & 0 deletions inst/examples/Button3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

# Example 3
library(shiny)
library(shiny.fluent)
library(shinyjs)

# This example app shows how to use a Fluent UI Button to trigger a file upload.
# File upload is not natively supported by shiny.fluent so shinyjs is used
# to trigger the file upload input.
ui <- function(id) {
ns <- NS(id)
fluentPage(
useShinyjs(),
Stack(
tokens = list(
childrenGap = 10L
),
horizontal = TRUE,
DefaultButton.shinyInput(
inputId = ns("uploadFileButton"),
text = "Upload File",
iconProps = list(iconName = "Upload")
),
div(
style = "
visibility: hidden;
height: 0;
width: 0;
",
fileInput(
inputId = ns("uploadFile"),
label = NULL
)
)
),
textOutput(ns("file_path"))
)
}

server <- function(id) {
moduleServer(id, function(input, output, session) {
observeEvent(input$uploadFileButton, {
click("uploadFile")
})

output$file_path <- renderText({
input$uploadFile$name
})
})
}

if (interactive()) {
shinyApp(ui("app"), function(input, output) server("app"))
}
45 changes: 45 additions & 0 deletions inst/examples/Button4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

# Example 4
library(shiny)
library(shiny.fluent)
library(shinyjs)

# This example app shows how to use a Fluent UI Button to trigger a file download.
# File download is not natively supported by shiny.fluent so shinyjs is used
# to trigger the file download.
ui <- function(id) {
ns <- NS(id)
fluentPage(
useShinyjs(),
DefaultButton.shinyInput(
inputId = ns("downloadButton"),
text = "Download",
iconProps = list(iconName = "Download")
),
div(
style = "visibility: hidden;",
downloadButton(ns("download"), label = "")
)
)
}

server <- function(id) {
moduleServer(id, function(input, output, session) {
observeEvent(input$downloadButton, {
click("download")
})

output$download <- downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep="")
},
content = function(file) {
write.csv(iris, file)
}
)
})
}

if (interactive()) {
shinyApp(ui("app"), function(input, output) server("app"))
}
99 changes: 99 additions & 0 deletions man/Button.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/DetailsList.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/Slider.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/TextField.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98c27cb

Please sign in to comment.