我遇到了一个问题,即单击dateInput
字段末尾的“ X”会清除字段本身,但不会将input
值记录为空白或NA。< / p>
以这个例子为例:
library(shiny)
ui <- fluidPage(
headerPanel("Example"),
mainPanel(
# input field
dateInput("user_text", label = "Date:", value = NA),
# display text output
textOutput("text"))
)
server <- function(input, output) {
# reactive expression
text_reactive <- reactive({
format(input$user_text)
})
observe({
print(format(input$user_text))
})
# text output
output$text <- renderText({
text_reactive()
})
}
shinyApp(ui = ui, server = server)
选择日期会将日期打印到output$text
和控制台上。突出显示日期并正确按键盘上的Delete或Backspace键可清除该单元格中的值,并将“”记录为output$text
的值。单击dateInput
字段末尾的“ X”,而不是使用退格或删除来清除值。这样可以正确清除字段本身,但将上次选择的日期保留为output$text
的值。
这是一个错误还是有办法让点击“ X”将output$text
的值设置为“”?
答案 0 :(得分:1)
我知道这不是您的原始问题,但是“ X”仅出现在IE 10和11中-请参见How to hide the Clear button in Internet Explorer 10。除非我缺少某些东西,否则它似乎不会影响Shiny中的反应物/观察值,但可以将其删除。请参阅this answer和该问题的其他一些信息。
library(shiny)
ui <- fluidPage(
headerPanel("Example"),
mainPanel(
# input field
dateInput("user_text", label = "Date:", value = NA),
# display text output
textOutput("text")),
tags$style('::-ms-clear { display: none; }')
)
server <- function(input, output) {
# reactive expression
text_reactive <- reactive({
format(input$user_text)
})
observe({
print(format(input$user_text))
})
# text output
output$text <- renderText({
text_reactive()
})
}
shinyApp(ui = ui, server = server)
添加的行是tags$style('::-ms-clear { display: none; }')