带输入的 R闪亮仪表板可折叠菜单项

2024-04-28

我正在尝试实施一个fileInput using library(shinydashboard)为用户提供上传文件的选项(就像完成的那样)here https://shiny.rstudio.com/articles/upload.html具有基本的闪亮 UI - 请查找下面的示例代码)。

我想放置fileInput in the dashboardSidebar在可扩展的menuItem,但不知道它应该进入闪亮的仪表板结构的哪里。

library(shiny)

ui <- fluidPage(
  titlePanel("Uploading Files"),
  sidebarLayout(
    sidebarPanel(
      fileInput("file1", "Choose CSV File",
                multiple = TRUE,
                accept = c("text/csv",
                           "text/comma-separated-values,text/plain",
                           ".csv")),
      tags$hr(),
      checkboxInput("header", "Header", TRUE),
      radioButtons("sep", "Separator",
                   choices = c(Comma = ",",
                               Semicolon = ";",
                               Tab = "\t"),
                   selected = ","),
      radioButtons("quote", "Quote",
                   choices = c(None = "",
                               "Double Quote" = '"',
                               "Single Quote" = "'"),
                   selected = '"'),
      tags$hr(),
      radioButtons("disp", "Display",
                   choices = c(Head = "head",
                               All = "all"),
                   selected = "head")
    ),
    mainPanel(
      tableOutput("contents")
    )
  )
)

server <- function(input, output) {
  output$contents <- renderTable({
    req(input$file1)
    df <- read.csv(input$file1$datapath,
                   header = input$header,
                   sep = input$sep,
                   quote = input$quote)
    if(input$disp == "head") {
      return(head(df))
    }
    else {
      return(df)
    }
  })
}

shinyApp(ui, server)

Edit:我稍微清理了一下代码区别 https://rstudio.github.io/shinydashboard/behavior.html#the-small-print-1在有孩子和无孩子之间menuItem参数更清晰expandedName and startExpanded只能与儿童一起使用menuItem相比之下tabName and selected仅与无子对象一起使用menuItem's.

library(shiny)
library(shinydashboard)

ui <- function(req) {
  dashboardPage(
    dashboardHeader(title = "Simple tabs"),
    dashboardSidebar(sidebarMenu(
      id = "sidebarItemSelected",
      menuItem(
        "Childfull menuItem",
        menuItem(
          "Childless menuItem 1",
          tabName = "childlessTab1",
          icon = icon("dashboard"),
          selected = TRUE
        ),
        fileInput("upload", "Upload"),
        bookmarkButton(),
        expandedName = "childfullMenuItem",
        startExpanded = TRUE
      ),
      menuItem(
        "Childless menuItem 2",
        icon = icon("th"),
        tabName = "childlessTab2",
        badgeLabel = "new",
        badgeColor = "green"
      )
    )),
    dashboardBody(tabItems(
      tabItem(tabName = "childlessTab1",
              h2("Dashboard tab content")),
      
      tabItem(tabName = "childlessTab2",
              h2("Widgets tab content"))
    ))
  )
}

server <- function(input, output, session) {
  observe({
    cat(
      paste(
        "\nsidebarItemSelected:",
        input$sidebarItemSelected,
        "\nsidebarItemExpanded:",
        input$sidebarItemExpanded,
        "\nsidebarCollapsed:",
        input$sidebarCollapsed,
        "\n"
      )
    )
  })
}

shinyApp(ui, server, enableBookmarking = "url")

初步回答:

当然 - 这是可能的(修改版本这个例子 https://rstudio.github.io/shinydashboard/structure.html#sidebar-menu-items-and-tabs):

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Simple tabs"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Dashboard", fileInput("upload", "Upload"), tabName = "dashboard", icon = icon("dashboard")),
      menuItem("Widgets", icon = icon("th"), tabName = "widgets",
               badgeLabel = "new", badgeColor = "green")
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName = "dashboard",
              h2("Dashboard tab content")
      ),
      
      tabItem(tabName = "widgets",
              h2("Widgets tab content")
      )
    )
  )
)

server <- function(input, output, session) {}

shinyApp(ui, server)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

带输入的 R闪亮仪表板可折叠菜单项 的相关文章

  • 多功能测试仪替代 system.time

    我已经看到 我认为是这样 使用了类似于 system time 的函数 它可以同时评估多个函数的时间并输出一个输出 我不记得它是什么 并且用我正在使用的术语进行互联网搜索并没有得到我想要的响应 有人知道我正在谈论的功能的名称 位置吗 你想要
  • 绘制点之间的所有线

    我有以下 R 代码 x lt c 0 01848598 0 08052353 0 06741172 0 11652034 y lt c 0 4177541 0 4042247 0 3964025 0 4074685 d lt data fr
  • twitterR 和 ROAuth R 软件包安装

    我在安装 CRAN 上的 twitteR 和 RAOuth 软件包时遇到一些问题 我尝试了几种不同的方法 在 Windows 下使用源代码 在 Ubuntu 下使用 RStudio 我尝试了以下命令 sudo apt get install
  • 在 R 中创建虚拟变量,排除某些情况为 NA

    我的数据看起来像这样 V1 V2 A 0 B 1 C 2 D 3 E 4 F 5 G 9 我想创建一个虚拟变量R where 0 1 1 2 3 4 and NA 0 5 9 应该很简单 有人可以帮忙吗 我们可以转换V2 into a fa
  • 以引用透明的方式从函数的省略号参数中提取符号

    事情又发生了 我正要按下发布答案按钮的问题被删除了 我正在寻找一种方法来从函数的省略号参数中提取绑定到符号的对象的值以及符号 也就是说 我试图以引用透明的方式从省略号中提取符号 我尝试过使用替代品和lazy dots 但没有成功 funct
  • 将每列的值乘以 R 中另一个 data.frame 中的权重

    我有两个data frames df and weights 代码如下 df看起来像这样 id a b d EE f 1 this 0 23421153 0 02324956 0 5457353 0 73068586 0 5642554 2
  • 在 R 中使用 lapply 绘制多个数据帧

    我正在尝试使用 lapply 函数绘制多个数据帧 每个数据帧一个图 但是尽管有关此主题的所有帖子我都找不到答案 因为我不断收到错误 图的输出列表为空 我的数据结构如下 df1 lt mtcars gt group by cyl gt tal
  • 只读取选定的列

    谁能告诉我如何仅读取下面每年数据的前 6 个月 7 列 例如使用read table Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2009 41 27 25 31 31 39 2
  • 将数据框中重叠的范围合并到唯一的组中

    我有一个 n 行 3 的数据框 df lt data frame start c 178 400 983 1932 33653 end c 5025 5025 5535 6918 38197 group c 1 1 2 2 3 df sta
  • 文本挖掘 pdf 文件/词频问题

    我正在尝试挖掘一篇具有丰富 pdf 编码和图表的文章的 pdf 我注意到 当我挖掘一些 pdf 文档时 我得到的高频词是 phi taeoe toe sigma gamma 等 它与某些 pdf 文档配合良好 但与其他文档配合使用时却得到这
  • 如何仅删除单括号并保留配对的括号

    你好 我亲爱的老师 R 用户朋友们 我最近开始认真学习正则表达式 最近我遇到了一种情况 我们只想保留配对括号 并省略未配对的 这是我的样本数据 structure list t1 c Book Pg 1 Website Online Jou
  • 如何获得所有大于x且有位置的数字?

    V lt c 1 3 2 4 2 3 1 X lt 3 pos lt V V X pos is 3 3 我需要的是所有 3 个的位置 I need 2 and 6 哪些职位是3 in V Use which pos lt which V 3
  • 如何从 R 中的 txt 文件读取矩阵?

    我有一个带有矩阵的txt文件 Matrix txt 重要 数字之间没有空格 0100 1001 1100 我想在 R 中将其作为矩阵读取 我该怎么做 我尝试使用 as matrix read table Matrix txt sep 但失败
  • 删除极坐标图边缘的多余空间和圆环

    我有一个极坐标图ggplot2我已经非常接近完成 相当简单的情节 我已经能够在删除矩形边框方面获得帮助 但我不需要删除最后一个范围轮廓与带有方位角标签的绘图周围的环之间的额外空间 我希望该图的边界为 15 000 而不是 15 214 我编
  • 实三次多项式的最快数值解?

    R 问题 寻找最快的方法来数值求解一堆已知具有实系数和三个实根的任意三次方程 据报道 R 中的 polyroot 函数对复杂多项式使用 Jenkins Traub 算法 419 但对于实多项式 作者参考了他们早期的工作 对于实三次或更一般的
  • 闭包作为数据合并习惯的解决方案

    我正在尝试解决闭包问题 而且我think我发现了一个案例 他们可能会有所帮助 我有以下几部分需要处理 一组正则表达式 旨在清理状态名称 位于函数中 具有州名称 上述函数创建的标准化形式 和州 ID 代码的 data frame 用于链接两者
  • 如何绘制具有显着性水平的箱线图?

    前段时间问了一个关于绘制箱线图的问题Link1 https stackoverflow com questions 14604439 plot multiple boxplot in one graph 我有一些包含 3 个不同组 或标签
  • 无法更改 RStudio 中的 R 版本

    我的 RStudio V 0 99 491 无法更改 R 版本 我以平常的方式行事Global Options gt R Version 然后它挂起并且不再工作或反应 R 运行良好的初始版本是R 3 1 0 我以前从未遇到过这样的问题 也许
  • 在 Shiny 中的用户会话之间共享反应数据集

    我有一个相当大的反应数据集 该数据集是通过轮询文件然后按预定义的时间间隔读取该文件而派生的 数据更新频繁 需要不断重新加载 诚然 重新加载可以增量完成并附加到 R 中的现有对象 但事实并非如此 然而目前 尽管会话中的数据相同 但此操作是针对
  • 线性判别分析图

    如何将样本 ID 行号 作为标签添加到此 LDA 图中的每个点 library MASS ldaobject lt lda Species data iris plot ldaobject panel function x y points

随机推荐