Simple text with dynamic part

Hi,
maybe I am a little bit confused, but I struggle building up a simple Text with a variable that is updated by running a method or input widget.
I thought about just taking a pn.pane.Markdown like this

import param
import holoviews as hv
import panel as pn
hv.extension('bokeh')
pn.extension()
class UpdateText(param.Parameterized):
    someinput = param.ObjectSelector(default = '0', objects=['0','1','2','3','4','5','6'])
         
    def dchg_explanation(self):
        text = pn.pane.Markdown("""
                                ###Selectet Discharge
                                The selected discharge is:  self.someinput ausgewählt. 
                                Some more text.""")
    
        return text
test = UpdateText()
pn.Row(test.param, test.dchg_explanation)

Maybe I just don’t know how to handle Markdown…
Maybe anyone can give me a hint.

Two things you have to do.

  1. make the function depends on someinput
  2. make the string an f-string.
import param
import panel as pn

pn.extension()


class UpdateText(param.Parameterized):
    someinput = param.ObjectSelector(
        default="0", objects=["0", "1", "2", "3", "4", "5", "6"]
    )

    @pn.depends("someinput")
    def dchg_explanation(self):
        text = pn.pane.Markdown(
            f"""
            ###Selectet Discharge
            The selected discharge is: {self.someinput} ausgewählt. 
            Some more text.
            """
        )
        return text


test = UpdateText()
pn.Row(test.param, test.dchg_explanation)
1 Like

Thx, that works!

1 Like