2017-03-01 3 views
0
ui <- fluidPage(
    sliderInput("obs", "Number of observations:", 
       min = 0, max = 1000, value = 500 
), 
    plotOutput("distPlot") 
) 

# Server logic 
server <- function(input, output) { 
    output$distPlot <- renderPlot({ 
    hist(rnorm(input$obs)) 
    }) 
} 

# Complete app with UI and server components 
shinyApp(ui, server) 

나는 사용자가 토글하고 관측 수를 선택할 수있는 sliderInput을 가진 간단한 응용 프로그램을 가지고 있습니다. 이 슬라이더 기능 위에 사용자가 원하는 수의 관측 값을 상자에 입력 할 수 있도록이 값을 수정하는 방법이 있습니까? 그 입력이 결과 히스토그램에 반영됩니까? 나는 슬라이더를 가질 수있는 유연성과 항상 슬라이더에 의존 할 필요없이 정확한 값을 신속하게 입력 할 수 있기를 원합니다.sliderInput을 반짝이는 방식으로 수정하여 사용자가 직접 값을 입력 할 수 있습니까?

답변

0

이와 비슷한?

ui <- fluidPage(
      numericInput("obs_numeric", "Number of observations", min = 0, max = 500, value = 500), 
      sliderInput("obs", "Number of observations:", 
         min = 0, max = 1000, value = 500 
      ), 
      plotOutput("distPlot") 
    ) 

    # Server logic 
    server <- function(input, output, session) { 
      output$distPlot <- renderPlot({ 
        hist(rnorm(input$obs)) 
      }) 
      observeEvent(input$obs, { 
        updateNumericInput(session, "obs_numeric", value = input$obs) 
      }) 
      observeEvent(input$obs_numeric, { 
        updateSliderInput(session, "obs", 
             value = input$obs_numeric) 
      }) 
    } 

    # Complete app with UI and server components 
    shinyApp(ui, server)