gpt4 book ai didi

r - 你如何清除 Shiny 的textInput框中的值

转载 作者:行者123 更新时间:2023-12-04 18:00:16 24 4
gpt4 key购买 nike

我有一个名为 addbtn 的 actionButton。单击此按钮时,它将从 textInput 框中获取输入并创建其他 textInput。

当我单击 addbtn 并创建 textInput 框时,需要清除 txtInput 框中的值,以便我可以添加更多 textInput 框。

这是代码:

界面:

ibrary(shiny)

shinyUI(

# Use a fluid Bootstrap layout
fluidPage(


# Generate a row with a sidebar
sidebarLayout(


# Define the sidebar with one input
sidebarPanel(
sliderInput("capacity", "Current Capacity:",
min=0, max=100, value=10),
c(list(
textInput("service", "Application Component Name", ""),
actionButton("addbtn", "Add Component"))),
#lapply(seq(10), function(i) uiOutput(paste0("ui", i)))

br(),
br(),
br(),
br(),
br(),
actionButton("calcbtn", "Calculate Projection")




),



# Create a spot for the barplot
mainPanel(
textInput("inputWork","Volume", width="200px"),
textInput("inputGrowth","Growth Rate", width="100px"),
lapply(seq(10), function(i) uiOutput(paste0("ui", i)))
#tags$p("Web"),
#verbatimTextOutput("input_type_text")

)

)
)
)

server <- function(input, output)
{
observeEvent(input$addbtn, {
n <- isolate(input$addbtn)
if (n == 0) return()

# create n-th pair of text input and output
output[[paste0("ui", n)]] <- renderUI(
list(textInput(paste0("textin", n), isolate(input$service)),
textOutput(paste0("textout", n))))
updateTextInput(input$service, "Application Component Name", value="")
})
}

使用这段代码,我得到了这些错误:

Warning: Error in $: $ operator is invalid for atomic vectors
Stack trace (innermost first):
64: updateTextInput
63: observeEventHandler [C:\shiny\bcl/server.R#11]
1: shiny::runApp
ERROR: [on_request_read] connection reset by peer

最佳答案

updateTextInput 中的所有问题

帮助

Arguments

session The session object passed to function given to shinyServer.

inputId The id of the input object.

label The label to set for the input object.

value The value to set for the input object.

所以你需要这样的服务器:

shinyServer(function(input, output,session) {

observeEvent(input$addbtn, {
n <- isolate(input$addbtn)
if (n == 0) return()

# create n-th pair of text input and output
output[[paste0("ui", n)]] <- renderUI(
list(textInput(paste0("textin", n), isolate(input$service)),
textOutput(paste0("textout", n))))
updateTextInput(session,"service", "Application Component Name", value="")
})
})

如果你不想改变 textInputlabel 你可以把它放在 update 中: updateTextInput(session,"service", value="")

关于r - 你如何清除 Shiny 的textInput框中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36286975/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com