data.table render.table

Published by onesixx on

https://shiny.posit.co/py/api/core/render.table.html#shiny.render.table

UX : ui.output_data_frame
SRVR: @ render.data_frame
– render.DataGrid
– render.DataTable

UX : ui.output_data_frame
SRVR : render.table

날짜가 숫자로 나오는 문제:

df[‘Date’] = df[‘Date’].dt.strftime(‘%Y-%m-%d’)

from shiny import (App, render, ui, Session, Inputs, Outputs, reactive, module)
import pandas as pd

df = pd.read_csv('./zzz/shiny/mtcars.csv')

app_ui = ui.page_fillable(
    ui.layout_columns(
        ui.output_data_frame("sixx_data_frame"),
        ui.output_data_frame("sixx_DataGrid"),
        ui.output_data_frame("sixx_DataTable"),
        ui.output_table("sixx_table"),
        col_widths= [6, 6, 6, 6]
    )
)

def server(input: Inputs, output: Outputs, session: Session):
    @render.data_frame
    def sixx_data_frame():
        return df
    
    @render.data_frame
    def sixx_DataGrid():
        return render.DataGrid(df, row_selection_mode='single')
       
    @render.data_frame
    def sixx_DataTable():
        return render.DataTable(df, 
            width='fit-content',height='200px',
            filters=False, row_selection_mode='multiple',
            #editable=True,
            summary=False,)    

    @render.table
    def sixx_table():
        return df   

app = App(app_ui, server)


FunctionDescription특징
render.data_frameDataFrame 형태로 출력
==> render.DataGrid그리드 형태로 출력데이터탐색을 위한
중간크기의 datasets
Offers sorting and filtering capabilities for interactive data exploration.
==>render.DataTableHTML 테이블로 변환하여 출력.interactive기능이 있는
대형 datasets 적합.
advanced features like pagination, searching, sorting, and filtering.
FunctionDescription특징
render.tableHTML 테이블로 변환하여 출력interactive기능이 없는 small datasetsNo additional features like sorting, filtering, or pagination.

가장 기본적인 테이블 출력 기능을 제공.
dataframe을 Simple and straightforward 형태로 렌더링할 때 사용.
고급 기능 없음 (정렬, 페이징, 검색)
    @output
    @render.table
    def ehist_df_excel_1():
        area = input.ehist_select_area()
        print("--------------------------------------->", area)
        
        #df = pd.read_excel(f"{DATA_DIR}/process/{area}_daily.csv")
        df = pd.DataFrame()
        return df
        if area is not None:
            
            #ddf = ddf.fillna('') 
            ddf['분류'] = ddf['분류'].fillna('')
            ddf['반송건수'] = ddf['반송건수'].fillna(0).astype(int)
            # return dd류
            return (
                ddf.style.set_table_attributes(
                    'class="dataframe shiny-table table w-auto"'
                )
                .hide(axis="index")
                .format(
                    {
                        '반송건수': "{:.0f}",#"{:,.0f}", 
                        # "Total": "{0:0.1f}",
                        # "Tip": "{0:0.2f}",
                        # "Total_bill": "{0:0.3f}",
                        # "Tip_rate": "{0:0.2%}",
                    }
                )
                .set_table_styles(
                    [dict(selector="th", props=[("text-align", "right")])]
                )
            )
        else:
            return None

itable

https://mwouts.github.io/itables/quick_start.html

ipydatagrid

https://github.com/bloomberg/ipydatagrid

Categories: shiny

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x