-
Notifications
You must be signed in to change notification settings - Fork 14
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
vue3 reactive input values #6
Comments
This is genius: Perhaps somewhat interestingly I was thinking along the same lines but rather differently; the idea of making shiny inputs reactive had not occurred to me. I was just exploring possibilities in private repo to essentially mimic
I'm not sure I make complete sense. |
I invited you to the repo in question (jsdata). I genuinely do not know if what it aims to achieve is even a good idea to begin with, feel free to tell me (and be honest about it too). library(htmltools)
library(shiny)
library(jsdata)
random_string <- function(){
paste0(sample(letters, 10), collapse = "")
}
string <- as_jsdata(random_string(), id = "string")
ui <- fluidPage(
tags$head(
tags$script(src = "https://unpkg.com/@vue/[email protected]/dist/reactivity.global.js"),
),
useJsdata(),
includeDataset(string),
tags$script(
HTML("datasets._datasets = datasets._datasets.map(set => VueReactivity.reactive(set));",
"$(document).on('shiny:connected', function() {",
"VueReactivity.effect(() => {
document.getElementById('test').innerText = datasets.getDataset('string')
})",
"});")
),
h1(id = "test")
)
server <- function(input, output){
observe({
invalidateLater(2000)
new_string <- as_jsdata(random_string(), id = "string")
update_dataset(new_string)
})
}
shinyApp(ui, server) My thinking was that this might make it somewhat easier to make existing htmlwidgets support reactivity. |
(If you think this approach could work I can rename and move the package to this org) |
@JohnCoene I really like the idea of One example @FrissAnalytics and I discussed was using |
@JohnCoene #4 and https://gist.github.com/timelyportfolio/edd70a7e40c54442aaccd5f529427fdc potentially related for |
valtioAfter more thought, experimentation, and testing, I actually think example from above but with valtio
|
I have always wondered with both
vue
ormobx
+Shiny
how our workflows/architecture might change if Shiny JavaScript state inShiny.shinyapp.$inputValues
was reactive instead of a plain object. In earlier versions of JavaScript withoutproxy
, this idea is very limited in potential usage since added and deleted object properties are not tracked. However, withproxy
and the newest versions ofmobx
andvue
, we can track added or effectively replaceShiny.shinyapp.$inputValues
with a reactive version early in the session llife and reap the full benefits of JavaScript reactivity fairly cleanly.Questions
Shiny
proper would ever pursue a reactiveJS
state since it would have to choose which reactive state engine it would use. Is there potential forShiny
to make the choice based on active community and well-tested, stable JS dependencies forShiny
to have a reactive JS engine as its input state? Which library would most likely meet the requirements? I would think choosing an existing library would be better than developing one from scratch.Code
The text was updated successfully, but these errors were encountered: