shinyjs 不会隐藏使用 renderUI 创建的按钮
Posted
技术标签:
【中文标题】shinyjs 不会隐藏使用 renderUI 创建的按钮【英文标题】:shinyjs won't hide button created with renderUI 【发布时间】:2021-06-26 16:14:02 【问题描述】:我有一个使用 shinyproxy 制作的闪亮应用程序。
在server.R
上,我使用renderUI
创建了一些UI 元素,如下所示:
output$guess <- renderUI(
url <- a("Vai al sito", href = text_info()$url,target="_blank")
tagList(
div(h4("Osservazioni ancora da classificare:", count_obs()), style = "margin-left: 68%; color: #ff944d;"),
div(h1("Descrizione Business:"), tags$i(h2(paste(text_info()$info))),
tags$br(),
"Website:", url,
style = "margin-right: 5%;", class = "ui raised segment"),
tags$br(),
div(h3(paste("Proposta algoritmo:", text_info()$entity_class_name), style = "margin-right: 0%; color:orange")),
tags$br(),
h3(html("testo testo")),
div(selectInput("yncheck", "", choices = c("",data_lookup$entity_class_name)), style = "margin-left: 33%;"),
tags$br(),
div( style = "margin-left: 2%",
tags$button(
id = "ynapproved", style = "margin-right: 5%; color:green;",
class = "ui button check-button", "Approva", tags$i(class = "check icon")
),
tags$button(
id = "yndiscarded", style = "margin-right: 5%; color:red;",
class = "ui button check-button", "Scarta", tags$i(class = "times icon")
),
tags$button(
id = "ynsuspend", style = "margin-right: 5%; color:SlateBlue;",
class = "ui button check-button", "Sospendi", tags$i(class = "hand paper outline icon")
),
tags$br(),
tags$button(
id = "submit",style = "margin-top: 5%; margin-right: 3%",
class = "ui button submit-button", "Salva modifiche", tags$i(class = "save icon"))
)
)
)
和
ui.R
library(shiny)
library(shiny.semantic)
library(shinyalert)
library(shinyjs)
semanticPage(
title = "mYapp",
includeCSS("www/styles.css"),
suppressDependencies("bootstrap"),
useShinyalert(),
useShinyjs(),
div(
class = "ui center aligned grid",
div(
class = "ten wide column", align = "center",
div(
class = "ui clearing segment",
div(radioButtons(inputId = "ynswitch", label = "Scegli dataset",
choices = c("Dati1",
"Dati2",
"Dati3"),
selected='Dati1',
inline=TRUE),
style = "font-size: 13px; font-weight: bold; text-align:left;" ),
uiOutput("guess")
)
)
)
当用户单击名为ynswitch
的radioButtons
的特定值时,我想隐藏ynsuspended
按钮。
所以我尝试在server.R
中使用shinyjs
observeEvent(input$ynswitch,
if(input$ynswitch=='Dati2')
shinyjs::hide("ynsuspend")
)
但它不起作用。元素未隐藏。
谢谢
【问题讨论】:
您可能还需要else shinyjs::show("ynsuspend")
,否则一旦隐藏就无法再次显示。即使ui
中有useShinyjs()
,您是否也会遇到此问题?
是的,我在 ui 中有 useShinyjs。尝试了您的建议,但仍然无法正常工作
除非您发布完整的MRE,否则我们无法诊断问题
【参考方案1】:
感谢您的回答。
我使用delay
解决了shinyjs:
https://github.com/daattali/shinyjs/issues/166
【讨论】:
以上是关于shinyjs 不会隐藏使用 renderUI 创建的按钮的主要内容,如果未能解决你的问题,请参考以下文章
使用shinydashboard和shinyjs在tabBox中启动时隐藏tabPanel
使用 shinyjs 和 flexdashbord 动态显示/隐藏输入