user2906657
user2906657

Reputation: 541

using input variables in reactive part Rshiny

I quiet novice to Rshiny. I want to capture the information(variables) entered by the user and pass them to python script, which I would be calling in the R itself. But initially I need help in the server code, where I am not doing something correct in the reactive code part.

My code till now is:

library(shiny)
ui <- fluidPage(
  headerPanel( 
  titlePanel("RADP CR Prediction Tool"),
  br(),
  tags$head(tags$script(src = "message-handler.js")),
  textInput('Region', label = 'Enter the region'),
  textInput('Regulatory', label = 'Enter the regulatory status'),
  textInput('Description', label = 'Enter the description for the CR'),
  br(),
  br(),
  actionButton("goButton", "Go!"),
  mainPanel(

      # Output: Formatted text for caption ----
      h3(textOutput("caption", container = span)),

      # Output: Verbatim text for data summary ----
      verbatimTextOutput("summary"),

      # Output: HTML table with requested number of observations ----
      tableOutput("view")

    )
)

server <- function(input, output, session) {
region_input=reactive(input$Region)
regulatory_input <- reactive(input$Regulatory)
description_input <-reactive(input$Description)
observeEvent(input$do, {
    session$sendCustomMessage(type = 'testmessage',
      message = 'Thank you for clicking')
  })
}
shinyApp(ui, server)

When I run the code it gives me Error: unexpected symbol in: ") server"

I need to use the regulatory_input, description_input and region_input as R variables, so that I can do further analysis.

Upvotes: 0

Views: 454

Answers (1)

divibisan
divibisan

Reputation: 12165

You're missing a parentheses. You close the mainPanel and the headerPanel but you don't have a close parentheses for the fluidPage function.

You can see this in RStudio by putting the cursor after the ) on line 25, you will see that the open ( in headerPanel( is highlighted. You can also select you code and then hit ctrl I to indent it. You'll see that the server function is "inside" the fluidPage function.

This may seem like a small thing, but paying attention to details like this is critical for programming. In my experience, 9 times out of 10, when something isn't working, its some small thing like this I forgot.

As for the question in your title, the values of your inputs are already in a variable: input$ID_OF_INPUT. Just use that as you would any other variable. There is no reason to copy the value out of it with something like: variable <- reactive({input$id}). Just use input$id wherever you would use variable.

Upvotes: 1

Related Questions