Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用shinyjs::Reset重置自定义输入_Javascript_R_Shiny_Shinyjs - Fatal编程技术网

Javascript 使用shinyjs::Reset重置自定义输入

Javascript 使用shinyjs::Reset重置自定义输入,javascript,r,shiny,shinyjs,Javascript,R,Shiny,Shinyjs,我有一个用于自定义输入的闪亮模块,每次单击此按钮时,我都会尝试添加一个按钮来重置此自定义输入(界面和服务器)。下面是使用shinyjs::reset的示例: 应用程序R library(shinyjs) 图书馆(rintrojs) 图书馆(shinydashboard) 图书馆(shinyWidgets) 来源(“customTextInput.R”,local=TRUE,encoding=“UTF-8”) ui如果您检查text1的输入id,您将看到它显示为text1 textBloco 因

我有一个用于自定义输入的闪亮模块,每次单击此按钮时,我都会尝试添加一个按钮来重置此自定义输入(界面和服务器)。下面是使用shinyjs::reset的示例:

应用程序R

library(shinyjs)
图书馆(rintrojs)
图书馆(shinydashboard)
图书馆(shinyWidgets)
来源(“customTextInput.R”,local=TRUE,encoding=“UTF-8”)

ui如果您检查
text1
的输入id,您将看到它显示为
text1 textBloco

因此,要使您的
reset
正常工作,您可以将其更新为
reset(“text1 textBloco”)
,然后它应该正常工作

或者,您可以将
customerTestInput.R
ns('textBloco')
sprintf
更新为
id
,然后在
app.R
中使用
重置(“text1”)
。 因此
sprintf()
将类似于:

sprintf(    
            "
<form id='%s' autocomplete='off' class = 'form-group shiny-input-container' style = 'padding-top:%s; width:%s; height:%s;'>
    <label for='%s'>Custom text input</label>
        <input charset='UTF-8' type='text' class = 'form-control' 
        id='%s' data-slots=' ' value = \"%s\"  
        data-shinyjs-resettable-id='%s' data-shinyjs-resettable-type='Text' data-shinyjs-resettable-value='' required>
</form>", id, addTop, addWidth, addHeight, ns('textInput'), ns('textInput'), addValue, ns('textInput')))

      )
sprintf(
"
自定义文本输入
“、id、addTop、addWidth、addHeight、ns('textInput')、ns('textInput')、addValue、ns('textInput'))
)

非常感谢。事实上,我已经尝试过你的建议,但是,当你在标签里有一个输入时,事情就变得糟糕了。除此之外,我真正想做的是在可能的情况下再次渲染元素,因为重置只会将值设置为默认值,但我也需要将样式设置为默认值。
library(shinyjs)


{# UI Module -----

    customTextInputUI <- function(id, addWidth = "100%", addHeight="64px", addTop="5px", addValue = "") {

        if (is.null(addValue)){addValue <- ""}

        ns <- NS(id)

        return(

                fluidPage(

                    HTML(

                        sprintf(

"
<form id='%s' autocomplete='off' class = 'form-group shiny-input-container' style = 'padding-top:%s; width:%s; height:%s;'>
    <label for='%s'>Custom text input</label>
        <input charset='UTF-8' type='text' class = 'form-control' 
        id='%s' data-slots=' ' value = \"%s\"  
        data-shinyjs-resettable-id='%s' data-shinyjs-resettable-type='Text' data-shinyjs-resettable-value='' required>
</form>", ns('textBloco'), addTop, addWidth, addHeight, ns('textInput'), ns('textInput'), addValue, ns('textInput')))

                )

          )

    }

}

sprintf(    
            "
<form id='%s' autocomplete='off' class = 'form-group shiny-input-container' style = 'padding-top:%s; width:%s; height:%s;'>
    <label for='%s'>Custom text input</label>
        <input charset='UTF-8' type='text' class = 'form-control' 
        id='%s' data-slots=' ' value = \"%s\"  
        data-shinyjs-resettable-id='%s' data-shinyjs-resettable-type='Text' data-shinyjs-resettable-value='' required>
</form>", id, addTop, addWidth, addHeight, ns('textInput'), ns('textInput'), addValue, ns('textInput')))

      )