Hi there,
I am learning shiny for python. I know that using shinyswatch I can import themes from bootswatch.
However, I would like to know how to apply classes to ui elements. For example the navbar (e.g.
bg-primary vs bg-light) or for example to input_action_button (e.g. btn-primary vs btn-outline-primary
).
My aim is to be able to create the same ui both in R and in Python. However, in R bslib I can use "class=" for actionbutton and bs_theme( "navbar-bg"="black") for the navbar background color. Is there anything similar in shiny for python?
Thank you so much.
Hi there, I answer my own question. I found an answer here using class_:
Here an example:
import matplotlib.pyplot as plt
import numpy as np
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
app_ui = ui.page_fluid(
ui.input_slider("n", "Number of observations", min=0, max=1000, value=500),
ui.input_action_button("go", "Go!", class_="btn-success"),
ui.output_plot("plot"),
)
def server(input: Inputs, output: Outputs, session: Session):
@output
@render.plot(alt="A histogram")
# Use reactive.event() to invalidate the plot only when the button is pressed
# (not when the slider is changed)
@reactive.event(input.go, ignore_none=False)
def plot():
np.random.seed(19680801)
x = 100 + 15 * np.random.randn(input.n())
fig, ax = plt.subplots()
ax.hist(x, bins=30, density=True)
return fig
app = App(app_ui, server)
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.