Reputation: 199
I'm new to shiny and i don't know anything about html, I'm having an issue to find a way to get a slider and a numeric input at the same time for the same input value in my app. Also I would like that when i for instance set the numeric value to 25 the slider automatically sets itself to 25 once the button is pushed. Thank you for your help. I tried that for my ui but it doesn't work ...
library(shiny)
shinyUI(fluidPage(
numericInput(inputId = "num1",
label = "Jour limite",
value = 10, min = 1, max=500),
sliderInput(inputId = "num",
label= "Jour limite",
value= 10 ,min=1 ,max=500
),
actionButton(inputId="clicks",
label= "Actualiser"),
plotOutput("courbj")
))
Don't know if it's relevant but here is my server code :
print(getwd())
CourbeTot <- read.table("data/CourbeTot.csv",header=TRUE,sep=";")
shinyServer(
function(input,output) {
valeur <- eventReactive(input$clicks, {
(input$num)
})
output$courbj <- renderPlot({
plot(CourbeTot$DFSurvieTot.time,CourbeTot$DFSurvieTot.ProptionAuDelaDe,xlim=c(1,2*valeur()))
})
})
Upvotes: 2
Views: 2185
Reputation: 17648
You can try to set a reactive Input (slider and numeric) using renderUI
on server site.
here the UI.R
library(shiny)
shinyUI(fluidPage(
uiOutput("INPUT"),
uiOutput("SLIDER"),
plotOutput("courbj")
))
Here the Server.R
.
library(shiny)
print(getwd())
CourbeTot <- 1:10
shinyServer(
function(input,output) {
valeur <- reactive({
S <- input$num
N <- input$num1
max(c(10,S,N))
})
output$courbj <- renderPlot({
plot(c(CourbeTot,valeur()))
})
# rective slider and numeric input
output$SLIDER = renderUI({
sliderInput(inputId = "num",
label= "Jour limite",
value= valeur() ,min=1 ,max=500)
})
output$INPUT = renderUI({
numericInput(inputId = "num1",
label = "Jour limite",
value = valeur(), min = 1, max=500)
})
})
As you provided no reproducible example I created one. Slider and numeric Input will change according to the other, respectively. This is done 1. per the max
function which will alwas output the highest value set by one of the two inputs. And. 2 that the inputs are moved to the server side using the renderUI
. You see that I removed the click button because of problems with the initial NULL
behavior. Upon this error you can't (or I found no way) select one value and update the other after the click. This seems to be a shiny bug asked already here. The code is not perfect, but I think it is a good basis to play around and you can adjust it for your purpose.
Upvotes: 2