Git Product home page Git Product logo

Comments (8)

gadenbuie avatar gadenbuie commented on May 28, 2024

Hi @stla and thanks for including a reprex with your issue! I've tried your example with shiny 1.7.1, 1.8.0, and the latest version from main and in all three cases the example seems to be working.

Can you clarify what you mean by "doesn't work anymore"? In my case, I noticed some unusual behavior with the select input not showing the B selection, but the server is correctly registering the choice indicating the the Shiny.bindAll() might have worked as expected.

from shiny.

stla avatar stla commented on May 28, 2024

It works for you?? For me the observer executing print(input$id) never prints anything. Also, when I open the console and I look at Shiny.shinyapp.$bindings, there's only dtable, not id.

from shiny.

gadenbuie avatar gadenbuie commented on May 28, 2024

It works for you?? For me the observer executing print(input$id) never prints anything.

Shoot, yeah, I do see this now trying again, sorry. I'm not sure why it looked like it was working before, maybe browser caching. I'll look into this.

from shiny.

gadenbuie avatar gadenbuie commented on May 28, 2024

@stla after a bit of digging, I've discovered that the issue isn't about async binding but rather about using selectize in this scenario. If you set selectize = FALSE in the selectInput(), the select input works as expected. But selectizeInput() doesn't work when passing through as.character().

library(shiny)

ui <- fixedPage(
  HTML(as.character(selectInput("id", label = NULL, choices = c("A", "B"))))
)

server <- function(input, output, session) {
  observe(print(input$id))
}

shinyApp(ui, server)

The issue is that the selectize dependencies are attached to the element returned by selectInput() and don't survive the as.character() coercion. If you want to use selectize as in your reprex, you can include its dependencies somewhere on the page, at which point your example works correctly.

ui <- fluidPage(
  br(),
  DTOutput("dtable"),
  shiny:::selectizeDependency()
)

from shiny.

gadenbuie avatar gadenbuie commented on May 28, 2024

That behavior hasn't changed recently, so one possibility is that you used this pattern in an app that happened to have another selectInput() elsewhere on the page and recently used the pattern in app without other select inputs.

from shiny.

stla avatar stla commented on May 28, 2024

Thanks! Alternatively, one can initialize the selectize input with this DT option:

    initComplete = JS(c(
      "function(settings){",
      "  $('#id').selectize();",
      "}"
    ))

but in order that it works, one needs to have a selectizeInput somewhere in the app. We can hide it if we don't want it.

from shiny.

stla avatar stla commented on May 28, 2024

I've found a better way. No need to add a selectizeInput in the app with this way:

library(shiny)
library(DT)
library(htmltools)

select_input <- selectInput("id", label = NULL, choices = c("A", "B"))
deps <- htmlDependencies(select_input)

dat <- data.frame(
  select = as.character(select_input)
)

ui <- fluidPage(
  br(),
  DTOutput("dtable"),
  tagList(deps)
)

from shiny.

gadenbuie avatar gadenbuie commented on May 28, 2024

Yeah, that general pattern is the way to go if you're coercing a shiny tag or tagList to character. I would recommend that you use htmltools::findDependencies() instead of htmltools::htmlDependencies(). findDependencies() recurses into the tag object, whereas htmlDependencies() reads the dependencies attached to the particular tag or object passed into it.

from shiny.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.