stリンク集

```python

import json
import pathlib
import datetime
import time
import math

# import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

import streamlit as st
import plotly.graph_objects as go
import plotly.express as px

import streamlit.components.v1 as components
import pyperclip


def display_tree(tree, selected_folders=None, level=0):
    if selected_folders is None:
        selected_folders = []

    for key, value in tree.items():
        if isinstance(value, dict):
            checkbox = st.checkbox(f"{'&nbsp;' * 12 * level}📁 {key}", key=f"{key}_folder")
            if checkbox:
                selected_folders.append((key, level))
                display_tree(value, selected_folders, level + 1)
        else:
            if value:  # リンクが存在する場合
                st.markdown(f"{'&nbsp;' * 12 * level}📄 {key}:{'&nbsp;' * 3} [リンクを開く]({value})", unsafe_allow_html=True)
            else:  # リンクが存在しない場合
                st.markdown(f"{'&nbsp;' * 12 * level}📄 {key}: （リンクなし）", unsafe_allow_html=True)
    
    return selected_folders

def st_display_categories(directory_tree):
    # CSSを使用して行間を狭くする
    st.markdown("""
    <style>
        .stMarkdown p {
            margin-bottom: 0px;
        }
        .stMarkdown {
            line-height: 2;
        }
        .stMarkdown a {
            text-decoration: none;
        }
    </style>
    """, unsafe_allow_html=True)

    # 3列のレイアウトを作成
    cols = st.columns(3)

    # カテゴリーを3列に分配
    for i, (category, links) in enumerate(directory_tree.items()):
        with cols[i % 3]:
            st.write('■ '+category)
            for name, url in links.items():
                st.markdown(f"[{name}]({url})", unsafe_allow_html=True)
            st.write("")  # カテゴリー間のスペース

def main():

    with st.expander("フォルダ風リンク集", expanded=True):
        directory_tree = {
            "category1": {
                "wikipedia": "https://en.wikipedia.org/wiki/Sushi",
                "Qita": "https://qiita.com/",
                "Qita2": "https://qiita.com/",
            },
            "category2": {
                "yahoo Japan": "https://www.yahoo.co.jp/",
                "google": "https://www.google.com/?hl=ja"
            },
            "category3": {
                "yahoo Japan": "https://www.yahoo.co.jp/",
                "google": "https://www.google.com/?hl=ja"
            },
            "category4": {
                "yahoo Japan": "https://www.yahoo.co.jp/",
                "google": "https://www.google.com/?hl=ja"
            },
            "category5": {
                "yahoo Japan": "https://www.yahoo.co.jp/",
                "google": "https://www.google.com/?hl=ja"
            }
        }
        
        # st.radioを使用して表示オプションを選択
        display_option = st.radio(
            "表示方法を選択",
            ["階層表示", "一覧表示"],
            horizontal=True,
            key="display_option"
        )

        if display_option == "階層表示":
            selected_folders = display_tree(directory_tree)
        else:
            st_display_categories(directory_tree)








    with st.expander("df風リンク集", expanded=True):
        # データフレームの作成
        data = [
            {"カテゴリ": "", "タイトル": "リンクA", "URL": "https://github.com/streamlit"},
            {"カテゴリ": "", "タイトル": "リンクB", "URL": "https://github.com/arnaudmiribel"},
            {"カテゴリ": "", "タイトル": "リンクC", "URL": "https://github.com/streamlit"},
            {"カテゴリ": "", "タイトル": "リンクD", "URL": "https://event.rakuten.co.jp/ochugen/point/weekend/?l-id=top_normal_flashbnr_10_BIEBCBJA_144883_1"},
        ]

        df2 = pd.DataFrame(data)


        # データフレームを表示し、リンク列を設定
        st.dataframe(
            df2,
            hide_index=True,
            column_config={
                "URL": st.column_config.LinkColumn(display_text="リンクを開く")
            }
        )










    with st.expander("単純なボタン", expanded=True):
        # HTMLのボタンとJavaScriptのポップアップを含むコード
        html_button_with_popup = """
        <!DOCTYPE html>
        <html>
        <head>
        <title>Button with Popup</title>
        <script>
        function displayPopup() {
        alert("ボタンがクリックされました！");
        }
        </script>
        </head>
        <body>

        <button onclick="displayPopup()">クリックしてください</button>

        </body>
        </html>
        """

        # Streamlitコンポーネントとして表示
        components.html(html_button_with_popup)
    










    with st.expander("エクスプローラーのリンク集", expanded=True):
        links1 = [
            {"category": "検索エンジン", "name": "Google", "url": r"\\LS410D3B6\PrivateDrive\Programming\Python\DevelopingEnv_streamlit"},
            {"category": "開発プラットフォーム", "name": "GitHub", "url": r"\\LS410D3B6\PrivateDrive\Programming\Python\DevelopingEnv_streamlit"},
            {"category": "NAS", "name": "streamlitフォルダ", "url": r"\\LS410D3B6\PrivateDrive\Programming\Python\DevelopingEnv_streamlit"},
            {"category": "NAS", "name": "jupyterフォルダ", "url": r"\\ls410d3b6\PrivateDrive\Programming\Python\DevelopingEnv_jupyter"},
        ]
        links2 = [
            {"category": "検索エンジン", "name": "Google", "url": r"\\LS410D3B6\PrivateDrive\Programming\Python\DevelopingEnv_streamlit"},
            {"category": "開発プラットフォーム", "name": "GitHub", "url": r"\\LS410D3B6\PrivateDrive\Programming\Python\DevelopingEnv_streamlit"},
            {"category": "NAS", "name": "streamlitフォルダ", "url": r"\\LS410D3B6\PrivateDrive\Programming\Python\DevelopingEnv_streamlit"},
            {"category": "NAS", "name": "jupyterフォルダ", "url": r"\\ls410d3b6\PrivateDrive\Programming\Python\DevelopingEnv_jupyter"},
        ]
        links = links1 + links2

        flag_NAS = st.checkbox("NAS", value=True)
        if flag_NAS==False:
            # NASカテゴリーのリンクを削除
            links = [link for link in links if link["category"] != "NAS"]

        flag_engine = st.checkbox("検索エンジン", value=True)
        if flag_engine==False:
            # 検索エンジンカテゴリーのリンクを削除
            links = [link for link in links if link["category"] != "検索エンジン"]



        html_links_table = """
        <!DOCTYPE html>
        <html lang="ja">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>リンク集</title>
            <script>
            function copyToClipboard(elementId) {
                var element = document.getElementById(elementId);
                var link = element.textContent;
                navigator.clipboard.writeText(link).then(function() {
                    var notification = document.getElementById('copyNotification');
                    notification.textContent = "コピーされました: " + link;
                    notification.style.display = 'block';
                    setTimeout(function() {
                        notification.style.display = 'none';
                    }, 2000);
                }, function(err) {
                    console.error('コピーに失敗しました:', err);
                });
            }
            </script>
            <style>
            body {
                font-family: 'Arial', sans-serif;
                margin: 0;
                padding: 20px;
                color: #333;
            }
            .container {
                max-width: 800px;
                margin: 0;
                background-color: #ffffff;
                border-radius: 8px;
                box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
                overflow: hidden;
            }
            table {
                width: 100%;
                border-collapse: separate;
                border-spacing: 0;
                table-layout: fixed;
            }
            th, td {
                padding: 8px 12px;
                text-align: left;
                font-size: 14px;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                border-bottom: 1px solid #ddd; /* 行の罫線のみを追加 */
            }
            th {
                background-color: #004080;
                color: #ffffff;
                font-weight: bold;
                text-transform: uppercase;
            }
            th:nth-child(1), td:nth-child(1) { width: 20%; }
            th:nth-child(2), td:nth-child(2) { width: 30%; }
            th:nth-child(3), td:nth-child(3) { width: 30%; }
            th:nth-child(4), td:nth-child(4) { width: 20%; }
            tr:nth-child(even) {
                background-color: #f2f2f2;
            }
            tr:hover {
                background-color: #e6f3ff;
            }
            a {
                color: #3498db;
                text-decoration: none;
                transition: color 0.3s ease;
            }
            a:hover {
                color: #2980b9;
                text-decoration: underline;
            }
            button {
                background-color: #2ecc71;
                color: white;
                border: none;
                padding: 4px 8px;
                border-radius: 4px;
                cursor: pointer;
                transition: background-color 0.3s ease;
                font-size: 12px;
                width: 100%;
            }
            button:hover {
                background-color: #27ae60;
            }
            #copyNotification {
                display: none;
                margin-top: 10px;
                padding: 8px;
                text-align: center;
                color: #2ecc71;
                font-size: 14px;
                font-weight: bold;
            }
            </style>
        </head>
        <body>
            <div class="container">
                <table>
                    <thead>
                        <tr>
                            <th>カテゴリー</th>
                            <th>リンク名</th>
                            <th>リンク</th>
                            <th>アクション</th>
                        </tr>
                    </thead>
                    <tbody>
        """

        for i, link in enumerate(links):
            html_links_table += f"""
                        <tr>
                            <td>{link['category']}</td>
                            <td>{link['name']}</td>
                            <td><a href="{link['url']}" target="_blank">{link['url']}</a></td>
                            <td><button onclick="copyToClipboard('link{i}')">copy</button></td>
                        </tr>
                        <tr style="display:none">
                            <td colspan="4"><span id="link{i}">{link['url']}</span></td>
                        </tr>
            """

        html_links_table += """
                    </tbody>
                </table>
                <div id="copyNotification"></div>
            </div>
        </body>
        </html>
        """

        table_height = len(links) * 40 + 150

        components.html(html_links_table, height=table_height)









    with st.expander("スマホ風のリンク集", expanded=True):
        html_links_table = """
            <!DOCTYPE html>
            <html lang="ja">
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>スマートフォン風ブックマーク</title>
                <style>
                    body {
                        font-family: Arial, sans-serif;
                        background-color: #ffffff;
                        margin: 0;
                        padding: 20px;
                    }
                    .container {
                        display: grid;
                        grid-template-columns: repeat(4, 1fr);
                        gap: 20px;
                        max-width: 400px;
                        margin: 0 auto;
                    }
                    .bookmark {
                        display: flex;
                        flex-direction: column;
                        align-items: center;
                        text-decoration: none;
                        color: #333;
                    }
                    .icon {
                        width: 60px;
                        height: 60px;
                        border-radius: 15px;
                        display: flex;
                        justify-content: center;
                        align-items: center;
                        margin-bottom: 5px;
                        font-weight: bold;
                        color: white;
                        font-size: 16px;
                    }
                    .label {
                        font-size: 12px;
                        text-align: center;
                    }
                </style>
            </head>
            <body>
                <div class="container">
                    <a href="https://qiita.com" class="bookmark" target="_blank" rel="noopener noreferrer">
                        <div class="icon" style="background-color: #55C500;">Q</div>
                        <span class="label">Qiita</span>
                    </a>
                    <a href="https://zenn.dev" class="bookmark" target="_blank" rel="noopener noreferrer">
                        <div class="icon" style="background-color: #3EA8FF;">Z</div>
                        <span class="label">Zenn</span>
                    </a>
                    <a href="https://spacenews.com" class="bookmark" target="_blank" rel="noopener noreferrer">
                        <div class="icon" style="background-color: #1E2A4A;">SN</div>
                        <span class="label">SpaceNews</span>
                    </a>
                    <a href="https://www.amazon.co.jp" class="bookmark" target="_blank" rel="noopener noreferrer">
                        <div class="icon" style="background-color: #FF9900;">A</div>
                        <span class="label">Amazon</span>
                    </a>
                    <a href="https://www.yahoo.co.jp" class="bookmark" target="_blank" rel="noopener noreferrer">
                        <div class="icon" style="background-color: #FF0033;">Y!</div>
                        <span class="label">Yahoo!</span>
                    </a>
                    <!-- 必要に応じて追加のブックマークを追加できます -->
                </div>
            </body>
            </html>
        """
        components.html(html_links_table, height=table_height)










    with st.expander("WEBリンク集", expanded=True):
        html_code = """
        <!DOCTYPE html>
        <html lang="ja">
        <head>
            <meta charset="UTF-8">
            <title>おしゃれなURLリスト</title>
            <style>
                body {
                    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
                    margin: 0;
                    padding: 20px;
                }

                .link-list {
                    width: 100%;
                    max-width: 800px;
                    margin: 0 auto;
                }

                .link-item {
                    display: flex;
                    align-items: flex-start;
                    padding: 15px;
                    margin-bottom: 15px;
                    background: #1e1e1e;
                    border-radius: 8px;
                    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
                    transition: background 0.3s;
                }

                .link-item:hover {
                    background: #333;
                }

                .link-icon {
                    font-size: 24px;
                    margin-right: 15px;
                }

                .link-content {
                    display: flex;
                    flex-direction: column;
                    width: 100%;
                }

                .link-title {
                    font-size: 18px;
                    color: #ffffff;
                    margin-bottom: 5px;
                }

                .link-description {
                    font-size: 14px;
                    color: #bbbbbb;
                    margin-bottom: 5px;
                }

                .link-url {
                    font-size: 14px;
                    color: #4caf50;
                }

                a {
                    text-decoration: none;
                    display: flex;
                    width: 100%;
                }
            </style>
        </head>
        <body>
            <div class="link-list">
                <div class="link-item">
                    <a href="https://qiita.com/KNR109/items/b5dad056da9b227041b" target="_blank" rel="noopener noreferrer">
                        <div class="link-icon">🌐</div>
                        <div class="link-content">
                            <div class="link-title">【2024年最新版】ブックマークすべきGitHubリポジトリまとめ - Qiita</div>
                            <div class="link-description">はじめに今回は最新の有益GitHubリポジトリを紹介します。プログラミング初心者から上級者まで学ぶことができるリポジトリを厳選しています。</div>
                            <div class="link-url">https://qiita.com/KNR109/items/b5dad056da9b227041b</div>
                        </div>
                    </a>
                </div>
                <div class="link-item">
                    <a href="https://qiita.com/KNR109/items/160e7d14ef5d08a88a8f" target="_blank" rel="noopener noreferrer">
                        <div class="link-icon">🌐</div>
                        <div class="link-content">
                            <div class="link-title">【2023年版】エンジニア向け読むべき資料まとめ - Qiita</div>
                            <div class="link-description">はじめに今回は無料で公開されているエンジニア向け資料をまとめました。資料の作り方も勉強になるので「勉強会で登壇している人」「企業の研修担当者」にもおすすめです。</div>
                            <div class="link-url">https://qiita.com/KNR109/items/160e7d14ef5d08a88a8f</div>
                        </div>
                    </a>
                </div>
            </div>
        </body>
        </html>
        """

        components.html(html_code, height=600)
    










if __name__ == "__main__":
    main()

```