Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In shiny how can I update an input text field with the value of an action button

Hi I want to create a shiny UI which a user can type in the name of a data-set into a text box say "testdataset". Then by clicking and action button to select a particular process in this (example) analysis 1 or analysis 2. Once this happens I want the text box to show the original data-set name plus the analysis chosen ie "testdataset-analysis1" . I've built and example UI below but Im new to R and shiny and dont know how to capture the events and pass the variables between the UI and the server and render them. can anyone help? example of what i would like to achieve
library(shiny)

  #====shiny UI
  shinyUI(pageWithSidebar(
    headerPanel("Shiny action button input "),
    sidebarPanel(
      textInput(inputId="data1", label = "Input data name"),

      actionButton("Ana1", "analysis1"),
      actionButton("Ana2", "analysis2")
    ),
    mainPanel(
  #
    )
  ))

  #====shiny server
  shinyServer(
    function(input, output) {
      output$data1 <- renderText({input$data1})

    })
  }
  )

  runApp()#to run application
like image 840
user5300810 Avatar asked Apr 02 '16 21:04

user5300810


People also ask

How do you use the shiny action button?

Action buttons and action links are meant to be used with one of observeEvent() or eventReactive() . You can extend the effects of an action button with reactiveValues() . Use observeEvent() to trigger a block of code with an action button. Use eventReactive() to update derived/calculated output with an action button.

How do you add text to the shiny app?

You can use tahs$h1() to h6() to add headings, or add text using textOutput(). You can add text using text within quotes(" ").

What is isolate in shiny?

The isolate function lets you read a reactive value or expression without establishing this relationship. The expression given to isolate() is evaluated in the calling environment. This means that if you assign a variable inside the isolate() , its value will be visible outside of the isolate() .


1 Answers

This is not a complete answer, but it is good to try for yourself. In general, use updateTextInput to update the text, use observeEvent to observe the click action on a button, use input$name to catch input values, and use output$name <- render... to set output. There are several updateInput methods that you can find in the official Shiny reference. http://shiny.rstudio.com/reference/shiny/latest/

For example, in your server code

function(session, input, output) {
    observeEvent(input$Ana1, {
        name <- paste(input$data1, "analysis 1")
        updateTextInput(session, "data1", value=name)
    }
}
like image 120
Xiongbing Jin Avatar answered Sep 28 '22 07:09

Xiongbing Jin