我有一个闪亮的应用程序,我在那里显示相同的输出多次。我有两个输入,他们都需要控制相同的输出。在我下面的例子中,输出是对方的副本,它必须保持这种方式。目前只有第一个输入做任何事情。我需要他们控制相同的输出,并对对方的变化作出React。
ui <- function(request) {
fluidPage(
textInput("txt1", "Enter text1"),
textInput("txt1", "Enter text2"),
checkboxInput("caps", "Capitalize"),
verbatimTextOutput("out1"),
verbatimTextOutput("out2"),
)
}
server <- function(input, output, session) {
output$out2<- output$out1 <- renderText({
if (input$caps)
toupper(input$txt1)
else
input$txt1
})
}
shinyApp(ui, server, enableBookmarking = "url")
2条答案
按热度按时间sd2nnvve1#
你需要给予你的输入唯一的ID,但是在你的代码中两个ID都是
txt1
。如果你改变这个,你可以使用正常的React性:6yt4nkrj2#
我遇到过类似的情况,需要多个相同的输入(尽管我只需要一个输出),它们总是具有相同的值。
对我来说,解决方案是创建一个电抗元件,它保存输入的值,并将值与输入同步。
即此代码始终使输入1和2具有相同的值