Skip to content

Commit

Permalink
docs: add upload ad download buttons examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Sobolewski committed May 18, 2023
1 parent 5462707 commit 20073d2
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
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
47 changes: 47 additions & 0 deletions inst/examples/Button3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

# 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 <- fluentPage(
useShinyjs(),
Stack(
tokens = list(
childrenGap = 10L
),
horizontal = TRUE,
DefaultButton.shinyInput(
inputId = "uploadFileButton",
text = "Upload File",
iconProps = list(iconName = "Upload")
),
div(
style = "
visibility: hidden;
height: 0;
width: 0;
",
fileInput(
inputId = "uploadFile",
label = NULL
)
)
),
textOutput("file_path")
)

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

output$file_path <- renderPrint({
input$uploadFile
})
}

shinyApp(ui, server)
38 changes: 38 additions & 0 deletions inst/examples/Button4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# 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 upload input.
ui <- fluentPage(
useShinyjs(),
DefaultButton.shinyInput(
"downloadButton",
text = "Download",
iconProps = list(iconName = "Download")
),
div(
style = "visibility: hidden;",
downloadButton("download", label = "")
)
)

server <- 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)
}
)
}

shinyApp(ui, server)
85 changes: 85 additions & 0 deletions man/Button.Rd

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

0 comments on commit 20073d2

Please sign in to comment.