需要对 Shiny 中的多个输出使用相同的输入
Need to use same input for multiple outputs in 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"))
),
渲染:
output$sh1o <- renderText(input$sh1)
据我了解,Shiny 不允许多次使用输入。
有什么方法可以实现吗?
能否将相同的输入分配给临时变量,然后再分配给输出?
Shiny 允许使用任意多次输入,但不能对输出元素使用相同的 outputId
。您可以重命名 textOutput
outputId
,方法是先添加选项卡的名称,使它们独一无二。
这是一个例子:
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)
我正在尝试使用 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"))
),
渲染:
output$sh1o <- renderText(input$sh1)
据我了解,Shiny 不允许多次使用输入。
有什么方法可以实现吗?
能否将相同的输入分配给临时变量,然后再分配给输出?
Shiny 允许使用任意多次输入,但不能对输出元素使用相同的 outputId
。您可以重命名 textOutput
outputId
,方法是先添加选项卡的名称,使它们独一无二。
这是一个例子:
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)