RShiny中的actionButton:重置值的替代选项
我读过一些主题,不可能用闪亮的软件包重置actionButton的值,但我找不到任何技巧来解决我的问题 我想用以下代码删除主面板中的文本和按钮:RShiny中的actionButton:重置值的替代选项,r,shiny,R,Shiny,我读过一些主题,不可能用闪亮的软件包重置actionButton的值,但我找不到任何技巧来解决我的问题 我想用以下代码删除主面板中的文本和按钮: library(shiny) shinyUI(fluidPage( titlePanel("Trying to reset text !"), sidebarLayout( sidebarPanel( actionButton("button1","Print text")
library(shiny)
shinyUI(fluidPage(
titlePanel("Trying to reset text !"),
sidebarLayout(
sidebarPanel(
actionButton("button1","Print text")
),
mainPanel(
textOutput("textToPrint"),
br(),
uiOutput("uiButton2")
)
)
))
shinyServer(function(input, output) {
output$textToPrint <- renderText({
if(input$button1==0) (return(""))
else (return("Button clicked"))
})
output$uiButton2 <- renderUI({
if(input$button1==0) (return ())
else (return(actionButton("button2","Reset text and this button")))
})
})
库(闪亮)
shinyUI(fluidPage)(
titlePanel(“尝试重置文本!”),
侧边栏布局(
侧栏面板(
操作按钮(“按钮1”,“打印文本”)
),
主面板(
text输出(“textToPrint”),
br(),
uiOutput(“uiButton2”)
)
)
))
shinyServer(功能(输入、输出){
输出$textToPrint感谢Joe Cheng,这里有一个很好的方法:
shinyServer(function(input, output) {
values <- reactiveValues(shouldShow = FALSE)
observe({
if (input$button1 == 0) return()
values$shouldShow = TRUE
})
observe({
if (is.null(input$button2) || input$button2 == 0)
return()
values$shouldShow = FALSE
})
output$textToPrint <- renderText({
if (values$shouldShow)
"Button clicked"
})
output$uiButton2 <- renderUI({
if (values$shouldShow)
actionButton("button2","Reset text and this button")
})
})
shinyServer(功能(输入、输出){
价值观