首页 > 解决方案 > sliderInput() 或 sliderTextInput() 是否有任何方法具有 NA 或 NULL 默认值?

问题描述

有没有办法让看起来像滑块的闪亮输入具有初始 NULL 或 NA 值?两者都sliderInput不允许sliderTextInput它们的默认值为空。

我很清楚selectInput允许这样做(默认为character(0)),但它的视觉风格对我一直在处理的应用程序无效。

输入后需要读取它们的值actionButton,其中将进行一些检查以确保用户调整了所有输入。

我有一些 javascript 的基础知识,但需要一些关于如何创建解决方法的指导。

示例最小应用程序:

library(shiny)
library(shinyWidgets)

UI <- fluidPage(
  
  sliderInput(
    "test_1",
    "Testing sliderInput",
    min = 1,
    max = 5,
    value = 3 # don't allow leaving empty, NA or NULL
  ),
  
  sliderTextInput(
    "test2",
    "Testing sliderTextInput",
    choices = c("1 - Least",
                "2 - Less",
                "3 - Middle",
                "4 - More",
                "5 - Most"),
    selected = NULL # allows NULL, but takes the first of 'choices' either way
  )
  
)

server <- function(input, output, session) {
  
}

shinyApp(UI, server)

标签: rshinyslidershinywidgets

解决方案


推荐阅读