Shiny - enter text into a helper function

I am new to Shiny and trying to build a more accessible input and output for the function I created. I give this to people who don't run R, trying to build something that performs my functions in the background, and then spits out the answer.

I am having problems with what I want, unfortunately, with a bunch of errors. However, here is my sharper question:

The actual function that I want to run accepts a name (in quotes "Last, First") and a number.

PredH("Last,First",650)

So, I want a brilliant application that takes a name input and a quantity input, which then launches this program, and then returns a data table with my answer back. So a couple of questions.

How do I get it in the correct form for input into my equation on the server side of the script, do I need to return it to a function so that it can be accessed using the $ table type access function? (Now I just print using the cat () function in the console for the function, but I know that this cannot be used for this type of application.

I want to return the data that can be obtained in the PredH14 $ table. How can I make it shiny?

Here is my code:

interface:

library(shiny)


shinyUI(pageWithSidebar(

  # Application title
  headerPanel("Miles Per Gallon"),

  # Sidebar with controls to select the variable to plot against mpg
  # and to specify whether outliers should be included
  sidebarPanel(
    textInput("playername", "Player Name (Last,First):", "Patch,Trevor"),
   radioButtons("type", "Type:",
                 list("Pitcher" = "P",
                      "Hitter" = "H"
                      )),

    numericInput("PAIP", "PA/IP:", 550),
    submitButton("Run Comparables")


  ),
    mainPanel(
    textOutput("name")
        )

Server:

library(shiny)

shinyServer(function(input, output) {

sliderValues <- reactive({


    data.frame(
      Name = c("name", "PA"),

        Value = c(as.character(playername),
                  PAIP),

        stringsAsFactors=FALSE)
  })

name=input[1,2] 
PAIP=input[2,2] 
testing <- function(name,PAIP){ 
a=paste(name,PAIP) 
return(a) }
output$name=renderText(testing$a)


})
+4
source share
1 answer

I'm not quite sure that I understood your question 100%, but I clearly see that you are interested in how to transfer user interface input to the server and, possibly, vice versa.

, , . ui.R:

1. input$playername
2. input$type 
3. input$PAIP

:

1. output$name

, sliderValues <- reactive(..) , - ... , . submit button . . Create a submit button for an input form. Forms that include a submit button do not automatically update their outputs when inputs change, rather they wait until the user explicitly clicks the submit button.

, :

# server.R
library(shiny)
shinyServer(function(input, output) {

  sliderValues <- reactive({
      result <- ... input$playername ... input$type ... input$PAIP
      return(result)
  })

  output$name <- renderPlot/renderText (... sliderValues...)
})

# ui.R
library(shiny)

shinyUI(pageWithSidebar(

  headerPanel("Miles Per Gallon"),

  sidebarPanel(
    textInput("playername" ... ),
    radioButtons("type" ... ),
    numericInput("PAIP" ... ), 
    submitButton("...")
  ),

  mainPanel(
    textOutput/plotOutput...("name")
  )
 ))

, , , .

library(shiny)
runExample('07_widgets')
+4

All Articles