python - How to use busy indicators with table output? - Stack Overflow

I’m trying to create a busy indicator while generating a table using ui.busy_indicators. However, the s

I’m trying to create a busy indicator while generating a table using ui.busy_indicators. However, the spinner does not appear when using ui.output_table. If I replace ui.output_table with ui.output_plot or ui.output_data_frame, the spinner works as expected. This makes me wonder if ui.busy_indicators is incompatible with ui.output_table.

import time
import numpy as np
import seaborn as sns
from shiny import App, render, ui
import pandas as pd

app_ui = ui.page_fluid(
    #ui.output_plot("plot"),
    ui.output_table("table"),
    ui.busy_indicators.use(),
)

def server(input):

    @render.plot
    def plot():
        time.sleep(3)
        sns.lineplot(x=np.arange(100), y=np.random.randn(100))
    
    @render.table
    def table():
        time.sleep(3)
        df = pd.DataFrame(np.random.randn(10, 10), columns=[f'col_{i}' for i in range(10)])
        return df

app = App(app_ui, server)

I’m trying to create a busy indicator while generating a table using ui.busy_indicators. However, the spinner does not appear when using ui.output_table. If I replace ui.output_table with ui.output_plot or ui.output_data_frame, the spinner works as expected. This makes me wonder if ui.busy_indicators is incompatible with ui.output_table.

import time
import numpy as np
import seaborn as sns
from shiny import App, render, ui
import pandas as pd

app_ui = ui.page_fluid(
    #ui.output_plot("plot"),
    ui.output_table("table"),
    ui.busy_indicators.use(),
)

def server(input):

    @render.plot
    def plot():
        time.sleep(3)
        sns.lineplot(x=np.arange(100), y=np.random.randn(100))
    
    @render.table
    def table():
        time.sleep(3)
        df = pd.DataFrame(np.random.randn(10, 10), columns=[f'col_{i}' for i in range(10)])
        return df

app = App(app_ui, server)
Share Improve this question edited Mar 2 at 22:48 Jan 10.2k6 gold badges21 silver badges33 bronze badges asked Feb 28 at 18:29 zackzack 133 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

Busy indicators are currently not working combined with ui.output_table(). For R Shiny, a similar issue was reported in rstudio/shiny#4169 and recently implemented in rstudio/shiny/pull/4172.

While this is not implemented in Shiny for Python, we can mimic what was implemented within the above PR: Add a class to the table output using Tag.add_class() and add CSS which essentially applies display: unset; to the relevant selector, it deactivates the otherwise used display: none; what disables the spinner.

import time
import numpy as np
from shiny import App, render, ui
import pandas as pd

app_ui = ui.page_fluid(
    ui.input_action_button("run_tbl", "Run table"),
    ui.output_table("table").add_class("shiny-table-output"),
    ui.busy_indicators.use(),
    ui.busy_indicators.options(spinner_type="bars2"),
    ui.tags.style(
        """
        /* Disable display:none; which is currently set on some outputs */
        [data-shiny-busy-spinners] .recalculating.shiny-html-output.shiny-table-output::after {
          display: unset;
        }
        /* Hide the pulse if there are spinners on the page */
        [data-shiny-busy-spinners][data-shiny-busy-pulse].shiny-busy:has(.recalculating.shiny-table-output)::after {
          display: none;
        }
        """
    )
)

def server(input):
    
    @render.table
    def table():
        input.run_tbl()
        time.sleep(3)
        df = pd.DataFrame(np.random.randn(10, 10), columns=[f'col_{i}' for i in range(10)])
        return df

app = App(app_ui, server)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745134120a4613117.html

相关推荐

  • python - How to use busy indicators with table output? - Stack Overflow

    I’m trying to create a busy indicator while generating a table using ui.busy_indicators. However, the s

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信