0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

yeah good point. Actually I am more into python. This R stuff came adhoc. I am running R code in simple R. I think you are correct. Should use Rstudio. Let me rectify and run the code again.
But still my questions-remains. How can capture the input values as R variables?
Yes I know that. But I have to store it in a variable for subsequent use. That is why I am using variable. Also input$Region gives object input not found
That's not actually what you're doing here. Read the help for ?reactive: reactive({input$Region}) doesn't return a value that can be stored in a variable, it returns a function that, when called (with region_input()since it's a function not a variable), returns the current value of input$Region. If you want to save the current value of input$Region in a consistent variable, you want to use isolate().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.