![]() ![]() In this section, we’ll explore these concepts more deeply. We’ve explained a bit about reactivity, but mostly glossed over the details. The previous examples have given you a good idea of what the code for Shiny applications looks like. ![]() Library(shiny) runExample( "03_reactivity") In this case that’s either one of the user input values ( input$dataset or input$obs). These expressions work similarly to the renderPlot expression used in the first example: by declaring a rendering expression you tell Shiny that it should only be executed when its dependencies change. ![]() Two other rendering expressions ( renderPrint and renderTable) that return the output$summary and output$view values.A reactive expression to return the dataset corresponding to the user choice.The server side of the application has also gotten a bit more complicated. # Define UI for dataset viewer app - ui <- fluidPage( # App title - titlePanel( "Shiny Text"), # Sidebar layout with a input and output definitions - sidebarLayout( # Sidebar panel for inputs - sidebarPanel( # Input: Selector for choosing dataset - selectInput( inputId = "dataset", label = "Choose a dataset:", choices = c( "rock", "pressure", "cars")), # Input: Numeric entry for number of obs to view - numericInput( inputId = "obs", label = "Number of observations to view:", value = 10) ), # Main panel for displaying outputs - mainPanel( # Output: Verbatim text for data summary - verbatimTextOutput( "summary"), # Output: HTML table with requested number of observations - tableOutput( "view") ) ) ) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |