Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
¿Cómo cambian los atributos de los elementos de la interfaz de usuario con JavaScript en Shiny?

Sé que existe este método del lado del servidor llamado renderUI, pero hace que la actualización de la interfaz de usuario sea extremadamente lenta en algunos casos, por lo que ahora confío en JavaScript.

Mi problema es el siguiente. Me gustaría actualizar el atributo de título de material_card del paquete shinymaterial. Me gustaría ver que el título cambie, cada vez que seleccione una alternativa de un menú desplegable separado.

Hasta ahora, mi lista de componentes de la interfaz de usuario contiene el objeto tags$script(), que se supone que debe observar los cambios en selectInput (va con id "desplegable").

Mi código se ve de la siguiente manera:

 library(shinymaterial) library(shiny) ui <- material_page( titlePanel("Soon to be working JavaScript example!"), sidebarLayout( sidebarPanel( selectInput( "dropdown", "Dropdown menu", c('Hat','Shoes','Jacket')), tags$script(' $(document).on("shiny:inputchanged", function(event) { if (event.name === "dropdown") { if(input.dropdown === "Jacket") { //Even this alert is not working, possibly because input.name is not recognized. :( alert("You chose Jacket, now the material card title will be changed to: Jacket selected"); //What am I supposed to put here to update the material_card title? } else { //...and here as well... } });' ), material_card( depth=5, title = 'This value needs to be changed according what was chosen in the dropdown menu!') ), mainPanel( h5('Nothing here!') ) ) ) server <- function(input, output) { #The server is empty, as it should. :) } shinyApp(ui = ui, server = server)

Logré que la alerta funcionara sin la validación if(input.dropdown === "Jacket"), pero esta validación no funciona: lo más probable es que input.dropdown ni siquiera se reconozca, aunque funciona bien con el panel condicional.

Además, estoy aún más perdido con la lógica: ¿cómo debo usar JavaScript para actualizar el título de material_card, después de que se haya observado el cambio en el valor selectInput (desplegable)?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Una brillante solución de solo interfaz de usuario:

 library(shinymaterial) library(shiny) dropdownChoices <- c('Hat','Shoes','Jacket') ui <- material_page( titlePanel("Soon to be working JavaScript example!"), sidebarLayout( sidebarPanel( selectInput( "dropdown", "Dropdown menu", dropdownChoices), material_card( depth = 5, title = lapply(dropdownChoices, function(i){ conditionalPanel(sprintf('input.dropdown == "%s"', i), i) }) )), mainPanel( h5('Nothing here!') ) ) ) server <- function(input, output) {} shinyApp(ui = ui, server = server)
about 4 years ago · Juan Pablo Isaza Report

0

library(shinymaterial) library(shiny) ui <- material_page( titlePanel("Soon to be working JavaScript example!"), sidebarLayout( sidebarPanel( selectInput( "dropdown", "Dropdown menu", c('Hat','Shoes','Jacket')), tags$script(HTML(' $(document).on("shiny:inputchanged", function(event) { if (event.name === "dropdown") { if(event.value === "Jacket") { alert("You chose Jacket, now the material card title will be changed to: Jacket selected"); $("#mycard>span.card-title").html("Here is the new card title"); } else { //...and here as well... } } });') ), material_card( depth=5, title = 'This value needs to be changed according what was chosen in the dropdown menu!', id = "mycard" ) ), mainPanel( h5('Nothing here!') ) ) ) shinyApp(ui, server = function(input,output){})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!