-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add upload ad download buttons examples
- Loading branch information
Jakub Sobolewski
committed
Jun 29, 2023
1 parent
96d2e9f
commit d07fffc
Showing
4 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.