|
| 1 | +from shiny import App, reactive, render, ui |
| 2 | + |
| 3 | +# Create the UI |
| 4 | +app_ui = ui.page_fluid( |
| 5 | + # Add Font Awesome CSS in the head |
| 6 | + ui.tags.head( |
| 7 | + ui.tags.link( |
| 8 | + rel="stylesheet", |
| 9 | + href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css", |
| 10 | + ) |
| 11 | + ), |
| 12 | + # Main layout |
| 13 | + ui.layout_column_wrap( |
| 14 | + ui.card( |
| 15 | + ui.card_header("Action Button Examples"), |
| 16 | + # Basic button with width parameter |
| 17 | + ui.input_action_button(id="btn1", label="Basic Button", width="200px"), |
| 18 | + ui.output_text("click_count_btn1"), |
| 19 | + ui.br(), # Add spacing |
| 20 | + # Button with icon and disabled state |
| 21 | + ui.input_action_button( |
| 22 | + id="btn2", |
| 23 | + label="Disabled Button with Icon", |
| 24 | + icon=ui.tags.i(class_="fa-solid fa-shield-halved"), |
| 25 | + disabled=True, |
| 26 | + ), |
| 27 | + ui.output_text("click_count_btn2"), |
| 28 | + ui.br(), # Add spacing |
| 29 | + # Button with custom class and style attributes |
| 30 | + ui.input_action_button( |
| 31 | + id="btn3", |
| 32 | + label="Styled Button", |
| 33 | + class_="btn-success", |
| 34 | + style="margin-top: 20px;", |
| 35 | + ), |
| 36 | + ui.output_text("click_count_btn3"), |
| 37 | + ), |
| 38 | + width="100%", |
| 39 | + ), |
| 40 | +) |
| 41 | + |
| 42 | + |
| 43 | +# Define the server |
| 44 | +def server(input, output, session): |
| 45 | + @render.text |
| 46 | + def click_count_btn1(): |
| 47 | + return f"Button 1 clicks: {input.btn1() or 0}" |
| 48 | + |
| 49 | + @render.text |
| 50 | + def click_count_btn2(): |
| 51 | + return f"Button 2 clicks: {input.btn2() or 0}" |
| 52 | + |
| 53 | + @render.text |
| 54 | + def click_count_btn3(): |
| 55 | + return f"Button 3 clicks: {input.btn3() or 0}" |
| 56 | + |
| 57 | + |
| 58 | +# Create and return the app |
| 59 | +app = App(app_ui, server) |
0 commit comments