useShinyInput(..., {type: "shiny.datetime"}): the client sends a number, the
server reads a datetime. The smallest demonstration of routing an input
through a Shiny input handler.
Every leaf below is one checkable claim about this app. [py] / [r] / [js]
mark a claim that holds only in that language; (test) marks a claim pinned by
a unit test; (verify) marks a claim not yet checked against the code.
- the hook's
typeappends:shiny.datetimeto the wire id, so the value arrives aswhen:shiny.datetimeand Shiny's built-in handler coerces it beforeinput.when()resolves - opting into a
typebypasses shinyreact's ownshinyreact.defaulthandler — the value is handled by Shiny's registry, not by shinyreact - the id/type pairing is a per-id contract: a second mount of
"when"withouttype(or with a different one) throws at hook mount
- one output,
when_info→"<type name> → <repr>", e.g."datetime → datetime.datetime(2026, 8, 28, 12, 0, tzinfo=...)" input.when()isNonebefore the first client message → returns"—"(em dash)- the example asserts nothing about the timezone the handler attaches
[py]only — this example has no R server; R's handler registry has noshiny.datetimeequivalent, so the client is not portable as written
- renders
nulluntiluseShinyInitialized()is true useShinyInput("when", Math.floor(Date.now() / 1000), {type: "shiny.datetime", debounceMs: 0})(test)- the default is unix seconds, not milliseconds — captured once at first mount
debounceMs: 0, so each keystroke in the number field is sent immediately
- a
<input type="number">bound to that value;onChangesendsNumber(e.target.value)(test)- an empty field yields
Number("") === 0, so clearing the box sends the unix epoch rather than nothing(test)
- an empty field yields
- shows the server's echo in a
<code>, or"…"before the first value - explanatory copy names
shiny.datetime,datetime, andinput.when()inline in<code>elements - no mount container in the page — the client appends its own
<div>to<body>