library("jrShiny") library("shiny")
Open chapter2/exercise6.Rmd
. This contains the answers to Exercise 5. Here we're calculating the variable selected
twice which is inefficient.
reactive()
function so that the variable selected
is only calculated once.Use chapter2/exercise6.Rmd
again.
actionButton()
and an eventReactive()
to make it so that the plot and text only render when the button is clicked. actionButton()
to actionLink()
Open chapter2/exercise8.Rmd
. Here we have one button for the flower setosa and one for versicolor. We've also set up a reactiveValues()
that initialises to the entire iris data set
* Use the observeEvent()
function to update the reactiveValues to the correctly filtered data set, depending on which button the user clicks
renderTable()
, add a static table of the selected datachapter2/exercise9.Rmd
and run. r
## Arguments: id, code to execute on the server
observeEvent(input$n, {
print(input$n)
}
)
and look at the R Markdown
tab. chapter2/exercise10a.Rmd
and run. n
in an rnorm
call, i.e. rnorm(input$n)
.renderPlot()
, generate a scatter plot of random numbers where the sample size is determined by a slider.chapter2/exercise10b.Rmd
and run. sliderInput()
widget to control the mean value used in the rnorm()
function call, i.e.
r
## input$mean comes from a second slider
rnorm(input$n, input$mean)
selectInput()
widget to switch between generating random numbers from
a normal distribution and a uniform distribution. For a uniform distribution you would use the runif()
function. renderText(input$n)
to the script to print the value of input$n
.input$n
, print out the largest value in the sample.chapter2/exercise11.Rmd
and run. reactive()
function.selectInput()
widget to switch between generating random numbers from a normal distribution
and a uniform distribution.chapter2/exercise12.Rmd
and run. eventReactive()
, only redraw the graph and calculate the maximum value when the Plot it
button is pressed.actionButton()
to actionLink()
chapter2/exercise13.Rmd
and run. reactiveValues()
and observeEvent()
to only redraw the plot when a button is clicked.When I was developing this tutorial, I created a couple of simple examples to illustrate different shiny components. These examples are found in chapter2/
and the files start with Why_
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.