Skip to content

Add server update functions to components using InputAdapter #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ Imports:
shiny.react (>= 0.4.0),
utils
Suggests:
chromote,
covr,
knitr,
lintr (>= 3.0.0),
purrr,
rcmdcheck,
rmarkdown,
shiny.router
shiny.router,
shinytest2,
testthat (>= 3.0.0),
withr
Config/testthat/edition: 3
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ export(renderReact)
export(runExample)
export(setInput)
export(triggerEvent)
export(updateCheckbox.shinyInput)
export(updateEditableText.shinyInput)
export(updateHTMLSelect.shinyInput)
export(updateInputGroup.shinyInput)
export(updateNumericInput.shinyInput)
export(updateRadioGroup.shinyInput)
export(updateRangeSlider.shinyInput)
export(updateSlider.shinyInput)
export(updateSwitch.shinyInput)
export(updateTextArea.shinyInput)
importFrom(shiny.react,JS)
importFrom(shiny.react,reactOutput)
importFrom(shiny.react,renderReact)
Expand Down
74 changes: 64 additions & 10 deletions R/components.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
#' @name component
NULL

#' Documentation template
#'
#' @param inputId The `input` slot that will be used to access the value.
#' @param ... Component props and children. See the official Blueprint docs for details.
#' @param value Initial value.
#' @param session The Shiny session object.
#'
#' @return
#' Object with `shiny.tag` class suitable for use in the UI of a Shiny app.
#'
#' @keywords internal
#' @name shinyInput
NULL

component <- function(name) {
function(...) {
shiny.react::reactElement(
Expand Down Expand Up @@ -233,14 +247,18 @@ Divider <- component("Divider")
#' Documentation: <https://blueprintjs.com/docs/#core/components/editable-text>
#'
#' @example inst/examples/EditableText.R
#' @inherit component params return
#' @inherit shinyInput params return
#' @export
EditableText <- component("EditableText")

#' @rdname EditableText
#' @export
EditableText.shinyInput <- input("EditableText", "") # nolint

#' @rdname EditableText
#' @export
updateEditableText.shinyInput <- shiny.react::updateReactInput # nolint

#' HTML elements
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/html>
Expand Down Expand Up @@ -515,20 +533,24 @@ Label <- component("Label")
#' Documentation: <https://blueprintjs.com/docs/#core/components/checkbox>
#'
#' @example inst/examples/Checkbox.R
#' @inherit component params return
#' @inherit shinyInput params return
#' @export
Checkbox <- component("Checkbox")

#' @rdname Checkbox
#' @export
Checkbox.shinyInput <- input("Checkbox", FALSE) # nolint

#' @rdname Checkbox
#' @export
updateCheckbox.shinyInput <- shiny.react::updateReactInput # nolint

#' Radio
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/radio>
#'
#' @example inst/examples/Radio.R
#' @inherit component params return
#' @inherit shinyInput params return
#' @export
Radio <- component("Radio")

Expand All @@ -540,45 +562,61 @@ RadioGroup <- component("RadioGroup")
#' @export
RadioGroup.shinyInput <- input("RadioGroup", NULL) # nolint

#' @rdname Radio
#' @export
updateRadioGroup.shinyInput <- shiny.react::updateReactInput # nolint

#' HTML select
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/html-select>
#'
#' @example inst/examples/HTMLSelect.R
#' @inherit component params return
#' @inherit shinyInput params return
#' @export
HTMLSelect <- component("HTMLSelect")

#' @rdname HTMLSelect
#' @export
HTMLSelect.shinyInput <- input("HTMLSelect", "") # nolint

#' @rdname HTMLSelect
#' @export
updateHTMLSelect.shinyInput <- shiny.react::updateReactInput # nolint

#' Slider
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/sliders.slider>
#'
#' @example inst/examples/Slider.R
#' @inherit component params return
#' @inherit shinyInput params return
#' @export
Slider <- component("Slider")

#' @rdname Slider
#' @export
Slider.shinyInput <- input("Slider", 0) # nolint

#' @rdname Slider
#' @export
updateSlider.shinyInput <- shiny.react::updateReactInput # nolint

#' Range slider
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/sliders.range-slider>
#'
#' @example inst/examples/Slider.R
#' @inherit component params return
#' @inherit shinyInput params return
#' @export
RangeSlider <- component("RangeSlider")

#' @rdname RangeSlider
#' @export
RangeSlider.shinyInput <- input("RangeSlider", c(0, 0)) # nolint

#' @rdname RangeSlider
#' @export
updateRangeSlider.shinyInput <- shiny.react::updateReactInput # nolint

#' Multi slider
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/sliders.multi-slider>
Expand All @@ -605,14 +643,18 @@ MultiSliderHandle <- properties("MultiSliderHandle")
#' Documentation: <https://blueprintjs.com/docs/#core/components/switch>
#'
#' @example inst/examples/Switch.R
#' @inherit component params return
#' @inherit shinyInput params return
#' @export
Switch <- component("Switch")

#' @rdname Switch
#' @export
Switch.shinyInput <- input("Switch", FALSE) # nolint

#' @rdname Switch
#' @export
updateSwitch.shinyInput <- shiny.react::updateReactInput # nolint

#' FileInput
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/file-input>
Expand All @@ -631,27 +673,35 @@ FileInput.shinyInput <- input("FileInput", "") # nolint
#' Documentation: <https://blueprintjs.com/docs/#core/components/numeric-input>
#'
#' @example inst/examples/NumericInput.R
#' @inherit component params return
#' @inherit shinyInput params return
#' @export
NumericInput <- component("NumericInput")

#' @rdname NumericInput
#' @export
NumericInput.shinyInput <- input("NumericInput", 0) # nolint

#' @rdname NumericInput
#' @export
updateNumericInput.shinyInput <- shiny.react::updateReactInput # nolint

#' Input group
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/text-inputs.input-group>
#'
#' @example inst/examples/InputGroup.R
#' @inherit component params return
#' @inherit shinyInput params return
#' @export
InputGroup <- component("InputGroup")

#' @rdname InputGroup
#' @export
InputGroup.shinyInput <- input("InputGroup", "") # nolint

#' @rdname InputGroup
#' @export
updateInputGroup.shinyInput <- shiny.react::updateReactInput # nolint

#' TagInput
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/tag-input>
Expand All @@ -670,14 +720,18 @@ TagInput.shinyInput <- input("TagInput", NULL) # nolint
#' Documentation: <https://blueprintjs.com/docs/#core/components/text-inputs.text-area>
#'
#' @example inst/examples/TextArea.R
#' @inherit component params return
#' @inherit shinyInput params return
#' @export
TextArea <- component("TextArea")

#' @rdname InputGroup
#' @export
TextArea.shinyInput <- input("TextArea", "") # nolint

#' @rdname InputGroup
#' @export
updateTextArea.shinyInput <- shiny.react::updateReactInput # nolint

#' Overlay
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/overlay>
Expand Down
2 changes: 1 addition & 1 deletion inst/www/blueprint.min.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions js/src/resizeSensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ const propTypes = {
};

const ResizeSensor = ({ inputId, content, ...propsRest }) => {
content.props.style.overflow = "auto";
content.props.style.resize = "both";
content.props = {
...content.props,
style: {
...(content.props.style || {}),
overflow: "auto",
resize: "both",
},
}
const handleResize = useCallback(([{ contentRect }]) => {
Shiny.setInputValue(inputId, contentRect);
});
Expand Down
9 changes: 9 additions & 0 deletions man/Checkbox.Rd

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

9 changes: 9 additions & 0 deletions man/EditableText.Rd

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

9 changes: 9 additions & 0 deletions man/HTMLSelect.Rd

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

16 changes: 16 additions & 0 deletions man/InputGroup.Rd

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

Loading