【问题标题】:Switch outputs in R shiny radio buttonsR闪亮单选按钮中的开关输出
【发布时间】:2019-01-31 09:40:34
【问题描述】:

我正在开发一个闪亮的应用程序,我正在使用来自 ShinyWidgets 的radioGroupButtons。因此,对于每个按钮,我都试图切换到不同的输出,如表格或绘图。如何将单选按钮链接到输出

library(shinyWidgets)
library(shinipsum)
library(htmlwidgets)

  ui <- navbarPage(
    div(
      id = "section1-1",
      radioGroupButtons(
        inputId = "Id069",
        # label = "Choose a graph :",
        choices = c(
          `<i class='fa fa-bar-chart'></i>` = "bar",
          `<i class='fa fa-line-chart'></i>` = "line",
          `<i class='fa fa-pie-chart'></i>` = "pie"
        ),
        justified = TRUE
      )
    )
  )

  server <- function(input, output, session) {
    # observe({
    #   x <- input$inRadioButtons
    #   
    #   # Can also set the label and select items
    #   updateRadioButtons(session, "inRadioButtons2",
    #                      label = paste("radioButtons label", x),
    #                      choices = x,
    #                      selected = x
    #   )
    # })
    output$plot <- renderPlot({
      random_ggplot()
    })
  }

  shinyApp(ui, server)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    在服务器端,您可以像这样访问输入 ID:

             Value = input$Id069
    

    因此,将这样的逻辑添加到服务器端(在 output$plot 中):

            If (Value == x) {
              Plot1()
            } else {
              Plot2()
            }
    

    您可能想查看 UI 上的条件面板。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-01
      • 1970-01-01
      • 2021-07-11
      • 2015-09-19
      • 2018-03-13
      • 2019-07-15
      • 2020-11-10
      • 2020-06-20
      相关资源
      最近更新 更多