需要对 Shiny 中的多个输出使用相同的输入

Raf*_*rra 4 r render shiny

我正在尝试使用 Shiny 中的选项卡编写一个应用程序,该应用程序引用来自文本框的相同输入。

输入:

column(2, textInput(inputId = "sh1", label = "Stakeholder #1's name"))

输出:

tabPanel("#1 vs #2",
                          fluidRow(
                              column(3),
                              column(2, textOutput(outputId = "sh1o")),
                              column(2, "vs"),
                              column(2, textOutput(outputId = "sh2o"))
                          ),

tabPanel("#1 vs #3",
                          fluidRow(
                              column(3),
                              column(2, textOutput(outputId = "sh1o")),
                              column(2, "vs"),
                              column(2, textOutput(outputId = "sh3o"))
                          ),
Run Code Online (Sandbox Code Playgroud)

渲染:

output$sh1o <- renderText(input$sh1)

据我所知,Shiny 不允许多次使用输入。

有什么办法可以使这项工作?

可以将相同的输入分配给临时变量,然后分配给输出吗?

Nic*_*icE 5

Shiny 允许根据需要多次使用输入,但不能outputId对输出元素使用相同的内容。您可以textOutput outputId通过首先添加选项卡的名称来重命名您的s 以使其唯一。

下面是一个例子:

library(shiny)
ui<-shinyUI(pageWithSidebar(
        headerPanel("Test"),
        sidebarPanel(textInput(inputId = "sh1", label = "Stakeholder #1's name")),
                mainPanel(
        tabsetPanel(
                tabPanel("#1 vs #2",
                         fluidRow(
                                 column(3),
                                 column(2, textOutput(outputId = "tab1_sh1o")),
                                 column(2, "vs"),
                                 column(2, textOutput(outputId = "tab1_sh2o"))
                         )),

                         tabPanel("#1 vs #3",
                                  fluidRow(
                                          column(3),
                                          column(2, textOutput(outputId = "tab2_sh1o")),
                                          column(2, "vs"),
                                          column(2, textOutput(outputId = "tab2_sh3o"))
                                  )
        )
))))

server <- function(input,output,session){
        output$tab1_sh1o <- renderText(input$sh1)
        output$tab1_sh2o <- renderText(input$sh1)
        output$tab2_sh1o <- renderText(input$sh1)
        output$tab2_sh3o <- renderText(input$sh1)
}
shinyApp(ui,server)
Run Code Online (Sandbox Code Playgroud)