How to associate the change of "$vuetify.theme.dark" to the change of another variable using vuetify3? #655
-
Hello! I am trying to run the code in example and I am having a hard time making this work using vuetify3. I am using the trame cookie-cutter and I was not able to make it run with vuetify2, it simply doesn't load, so I am trying to transpose it to vuetify3 but I don't know how to access the dark theme of the application using this new vuetify version. This is the code that I am using now:
Do you have any hint on this subject? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I put the answer here and below for reference import plotly.express as px
from trame.app import get_server
from trame.ui.vuetify3 import SinglePageWithDrawerLayout
from trame.ui.router import RouterViewLayout
from trame.widgets import router, plotly
from trame.widgets import vuetify3 as vuetify
# -----------------------------------------------------------------------------
# Charts
# -----------------------------------------------------------------------------
def scatter():
df = px.data.iris()
template = "plotly"
if state.theme_mode == "dark":
template = "plotly_dark"
fig = px.scatter(
df,
x="sepal_width",
y="sepal_length",
color="species",
template=template,
title="A Plotly Express Figure",
)
return fig
# -----------------------------------------------------------------------------
# Trame setup
# -----------------------------------------------------------------------------
server = get_server()
server.client_type = "vue3"
state, ctrl = server.state, server.controller
# -----------------------------------------------------------------------------
# Callbacks
# -----------------------------------------------------------------------------
@state.change("theme_mode")
def update_cube_axes_visibility(**kwargs):
ctrl.graph_update(scatter())
# -----------------------------------------------------------------------------
# GUI
# -----------------------------------------------------------------------------
# Home route
with RouterViewLayout(server, "/"):
with vuetify.VCard():
vuetify.VCardTitle("This is home")
with vuetify.VContainer(fluid=True, style="height: 600px;"):
with vuetify.VRow(dense=True):
vuetify.VSpacer()
figure = plotly.Figure(
display_logo=False,
display_mode_bar="true",
)
ctrl.graph_update = figure.update
vuetify.VSpacer()
# Foo route
with RouterViewLayout(server, "/foo"):
with vuetify.VCard():
vuetify.VCardTitle("This is foo")
with vuetify.VCardText():
vuetify.VBtn("Take me back", click="$router.back()")
# Bar/id
with RouterViewLayout(server, "/bar/:id"):
with vuetify.VCard():
vuetify.VCardTitle("This is bar with ID '{{ $route.params.id }}'")
# Main page content
with SinglePageWithDrawerLayout(server, theme=("theme_mode", "light")) as layout:
layout.title.set_text("Multi-Page demo")
with layout.toolbar:
vuetify.VSpacer()
vuetify.VCheckbox(
v_model=("theme_mode", "light"),
true_icon="mdi-lightbulb-off-outline",
false_icon="mdi-lightbulb-outline",
true_value="dark",
false_value="light",
classes="mx-1",
hide_details=True,
dense=True,
)
with layout.content:
with vuetify.VContainer():
router.RouterView()
# add router buttons to the drawer
with layout.drawer:
with vuetify.VList(shaped=True, v_model=("selectedRoute", 0)):
# vuetify.VSubheader("Routes")
with vuetify.VListItem(to="/"):
vuetify.VIcon("mdi-home")
vuetify.VListItemTitle("Home")
with vuetify.VListItem(to="/foo"):
vuetify.VIcon("mdi-food")
vuetify.VListItemTitle("Foo")
with vuetify.VListGroup(value=("true",), sub_group=True):
with vuetify.Template(v_slot_activator=True):
vuetify.VListItemTitle("Bars")
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
def main():
server.start()
if __name__ == "__main__":
main() |
Beta Was this translation helpful? Give feedback.
-
Vuetify cover the theme part in v3 here |
Beta Was this translation helpful? Give feedback.
I put the answer here and below for reference