Passing inputs from index.html to server with HTML Templates

I am trying to use HTML templates to build the UI for my shiny app, which utilizes sliders and radio buttons for most of the data inputs. However, I've been unable to get the server to read inputs from the sliders.

I found an example online which uses a numeric input to generate a histogram, but when I try to modify the index.html file to include a slider instead of a numeric input, the plot does not display and I get an "invalid arguments error." I suspect this has something to do with setting the name value of the numeric input which can't be read by the server. Swapping the ID/name of the numeric and slider inputs allows the app to work with the numeric input, but it will not work with the slider, even when they are the same number.


<!DOCTYPE html>

  <script src="shared/jquery.js" type="text/javascript"></script>
  <script src="shared/shiny.js" type="text/javascript"></script>
    {{ headContent() }}
    {{ bootstrapLib() }}

    <label>Distribution type:</label><br />
    <select name="dist">
      <option value="norm">Normal</option>
      <option value="unif">Uniform</option>
    <label>Number of observations:</label>
    <br />
    <input type="number" name="m" value="500" min="1" max="1000" />
    {{ sliderInput("n", "# of Observations", 400, 600, 500) }}

  <h3>Plot of data:</h3>
  <div id="plot" class="shiny-plot-output"
       style="width: 100%; height: 300px"></div>

R Server:

server <- function(input, output) {
  d <- reactive({
    dist <- switch(input$dist,
                   norm = rnorm,
                   unif = runif,
  output$plot <- renderPlot({
    dist <- input$dist
    n <- as.numeric(input$n)
         main = paste("r", dist, "(", n, ")", sep = ""),
         col = "#75AADB", border = "white")

shinyApp(ui = htmlTemplate("index.html"), server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.