Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
Can I force a shinyTree to be loaded when the app is started?

Summary: When I put a shinyTree (from the R package of the same name) in a dropdownButton (from the shinyWidgets package), it seems that the tree in question is not accessible from the input variable until the user has interacted with the tree in some way. Is there a way I can force the tree to load when the app is loaded at the start?

Here is a minimal (almost) example:

library(shiny)
library(shinyWidgets)
library(shinyTree)
library(magrittr)

render.as.text <- function(t) {
  if (is.null(t)) {
    'argument is NULL'
  } else {
    q <- get_selected(t)
    if (length(q) == 0) {
      'none selected'
    } else {
      paste(q, sep=', ', collapse=', ') 
    }
  }
}

ui <- fluidPage(
  dropdownButton(shinyTree('tree', checkbox=TRUE), circle=FALSE, inputId='dd')
)

server <- function(input, output, session) {
  output$tree <- renderTree({ list(OptionA = structure(list(OptionAA='', OptionAB=''), stopened=TRUE), OptionB='') })
  updateActionButton(session, 'dd', label='initial label')
  
  observe({
    updateActionButton(session, 'dd', label=render.as.text(input$tree))
  }) %>% bindEvent(input$dd_state)  
}

shinyApp(ui = ui, server = server)

When I run this app, the button begins with the text 'initial label' (as expected), then when I click on it the first time the text changes to 'argument is NULL' (showing that the variable input$tree has a NULL value), but the tree displays correctly in the dropdown. If I then click the button again to close the dropdown, the text 'argument is NULL' remains - it remains until I actually select one or more of the tree's checkboxes after which (and after clicking the button again) it will display either a comma-separated list of selected options or 'none selected' as expected.

I would very much like to be able to refer to input$tree beginning with the first time the user takes any action in the app - ideally I am looking for some command to insert in either the server or ui code (or both) which will mean that the first time the user clicks the button its text will change directly to 'none selected' because input$tree is no longer NULL. Is this possible?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Would just changing the default of your render.as.text function work for your purpose?

library(shiny)
library(shinyWidgets)
library(shinyTree)
library(magrittr)

render.as.text <- function(t) {
  if (is.null(t)) {
    'none selected'
  } else {
    q <- get_selected(t)
    if (length(q) == 0) {
      'none selected'
    } else {
      paste(q, sep=', ', collapse=', ') 
    }
  }
}

ui <- fluidPage(
  dropdownButton(shinyTree('tree', checkbox=TRUE), circle=FALSE, inputId='dd')
)

server <- function(input, output, session) {
  output$tree <- renderTree({ list(OptionA = structure(list(OptionAA='', OptionAB=''), stopened=TRUE), OptionB='') })
  updateActionButton(session, 'dd', label='initial label')
  
  observe({
    updateActionButton(session, 'dd', label=render.as.text(input$tree))
  }) %>% bindEvent(input$dd_state)  
}

shinyApp(ui = ui, server = server)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda