在闪亮的应用程序中使用范围滑块时,是否可以要求最小范围的选定值?我在ShinyWidgets包中使用了sliderTextInput()函数,但认为这对范围滑块是通用的。玩具示例代码:
testx=1:150
testy=1:150
library(shiny) # also requires shinyWidgets package be installed
ui <- fluidPage(
plotOutput("plot"),
shinyWidgets::sliderTextInput("range","Input Size:",
choices=c(1,25,50,100),
selected=c(25,50), grid = T)
)
server <- function(input, output) {
output$plot <- renderPlot({
plot(testx[input$range[1]:input$range[2]],testy[input$range[1]:input$range[2]],
xlim=c(0,150),ylim=c(0,150))
})
}
shinyApp(ui, server)
我要避免的问题是下面的问题,其中将滑块的两端设置为相同的值,这导致绘制单个点-我想选择一个范围。
答案 0 :(得分:0)
如果相同,则可以更新值:
testx=1:150
testy=1:150
library(shiny) # also requires shinyWidgets package be installed
library(shinyWidgets)
ui <- fluidPage(
plotOutput("plot"),
sliderTextInput("range","Input Size:",choices=sliderchoice,selected=c(25,50), grid = T)
)
server <- function(input, output,session) {
observeEvent(input$range,{
if(input$range[1] == input$range[2]){
updateSliderTextInput(session,"range",selected = c((input$range[1]-1),input$range[2]))
}
})
output$plot <- renderPlot({
plot(testx[input$range[1]:input$range[2]],testy[input$range[1]:input$range[2]],
xlim=c(0,150),ylim=c(0,150))
})
}
shinyApp(ui, server)