2

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()))
  })

})
PaoloH
  • 199
  • 11
  • I think you need something like this: http://stackoverflow.com/questions/21465411/r-shiny-passing-reactive-to-selectinput-choices – Roman Jul 21 '16 at 08:17
  • I don't understand why this is the same problem as me but to be fair i didn't exaclty understand what his problem was ( english is not my mother tongue sorry). But if i'm not mistaken his issue is a bit more complex than mine it seems. – PaoloH Jul 21 '16 at 08:35

1 Answers1

2

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.

Community
  • 1
  • 1
Roman
  • 17,008
  • 3
  • 36
  • 49
  • This looks like what I intended to do even if I may not have made myself very clear. I'll look into it to see if i can implement this in my app. Thank you. – PaoloH Jul 21 '16 at 12:30
  • Thanks for the answer, it worked for me, but I would also like to set the initial value of these two inputs. It seems that they always start with the min.value introduced previously. Is there any way to set a different starting point or an initial value for both of them?? – Elias Feb 11 '19 at 10:42