|>
mtcars ::group_by(cyl) |>
dplyr::summarise(mpg = round(mean(mpg), 2)) dplyr
# A tibble: 3 × 2
cyl mpg
<dbl> <dbl>
1 4 26.7
2 6 19.7
3 8 15.1
KIND learning network training materials by KIND learning network is licensed under CC BY-SA 4.0
July 3, 2024
"hello world!"
shiny
and reactlog
packagesapp.R
(conventional, but helpful)shiny
, and select the shinyapp
snippet to insert the boilerplate Shiny code ui
, where you’ll build your user interfaceserver
, where you’ll put the bulk of your R codeshinyApp
, which collects the ui
and server
, and runs your Shiny server"hello world!"
"hello world!"
in the ui
Ctrl
+ Shift
+ Enter
to run your code - or use the run app button Esc
to stop your app. You’ll need to stop and restart to see changes.server
. That’s going to do something simple with mtcars:renderTable
, output$
, and tableOutput
renderTable
function in server
renderTable
to a variable called output$my_table
"hello world!"
in the ui
with tableOutput("my_table")
Your code should now read:
Run it (Ctrl
+ Shift
+ Enter
) and you should see a table of mtcars data in the viewer pane:
renderX
etc?there are pairs of functions on the Shiny cheatsheet. Each output type has its own renderX
function, which you use in the server
to wrap other kinds of output. So renderPlot
collects plot
/ggplot
output etc.
once your output has been rendered, you then save it into a list variable called output
. Each bit of output needs its own variable name - like output$my_table
finally, and again from the Shiny cheatsheet, you extract your data inside the UI from the output$
variable by using an XOutput
function that corresponds to your renderX
radioButtons()
above your tableOutput
in the UI. You’ll need to comma-splice that - all your UI contents gets joined with commasradioButtons("my_input", "Which gear to show?", sort(unique(mtcars$gear)))
input$my_input