r光泽:隐藏和显示动词

发布于 2025-02-11 21:18:53 字数 1189 浏览 2 评论 0原文

我目前正在尝试创建一个带有多个标签面板的R Shiny应用程序。 在一个选项卡面板上,我想输入一些数字,然后根据按钮显示并隐藏输入的数字。 我使用shinyjs进行隐藏和动词,并获取数字,但是当我运行该应用程序时,在klick klick klick klick klick klick klick klick klick klick klick the Button上都不会发生。

有人知道如何解决这个问题吗?

这是我的代码的最低示例:

library(shiny)
library(shinyjs)

ui <- tagList(
  useShinyjs(),
  navbarPage(
    "shinyjs with navbarPage",
    tabPanel("tab1",
             actionButton("button1", "Click me"),
             div(id = "hello", "Hello!")),
    tabPanel("tab2",
             sidebarPanel(
               textInput('str_values', 'Enter values in comma delimited format (e.g. 5.6, 6.7, 4.1, ...)', "")),
             mainPanel(
               actionButton("button2", "Click me"),
               div(id = "div_values",verbatimTextOutput("oid_values")))
    )))

server <- function(input, output, session) {
  num_values <- reactive(as.numeric(unlist(strsplit(input$str_values,","))))
  
  observeEvent(input$button1, {
    toggle("hello")
  })
  
  observeEvent(input$button2, {
    toggle("div_values")
    output$oid_values <- renderPrint({
      cat("your output:\n")
      print(num_values())
    })
  })
}

shinyApp(ui, server)

I am currently trying to create an R Shiny app with multiple tab panels.
On one tab panel I would like to enter some numbers and then depending on a button show and hide the numbers entered.
I use shinyjs for the hiding and verbatimTextOutput to get the numbers but when I run the app nothing happens after klicking the button.

Does anyone know how to fix this?

Here is a minimum example of my code:

library(shiny)
library(shinyjs)

ui <- tagList(
  useShinyjs(),
  navbarPage(
    "shinyjs with navbarPage",
    tabPanel("tab1",
             actionButton("button1", "Click me"),
             div(id = "hello", "Hello!")),
    tabPanel("tab2",
             sidebarPanel(
               textInput('str_values', 'Enter values in comma delimited format (e.g. 5.6, 6.7, 4.1, ...)', "")),
             mainPanel(
               actionButton("button2", "Click me"),
               div(id = "div_values",verbatimTextOutput("oid_values")))
    )))

server <- function(input, output, session) {
  num_values <- reactive(as.numeric(unlist(strsplit(input$str_values,","))))
  
  observeEvent(input$button1, {
    toggle("hello")
  })
  
  observeEvent(input$button2, {
    toggle("div_values")
    output$oid_values <- renderPrint({
      cat("your output:\n")
      print(num_values())
    })
  })
}

shinyApp(ui, server)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文