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)?
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)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){})