r - 如何在 R Shiny 中将起始页设置为空?
问题描述
我想在我的 R 闪亮应用程序中将起始页面设置为空。我的意思是起始页不应该显示任何东西,除了搜索栏。然后,一旦在搜索栏中插入任何值,结果就会显示出来。我怎样才能做到这一点?我的代码在这里:
library(shiny)
library(shinydashboard)
library(shinyWidgets)
BB = read.table("first.csv", header = TRUE,sep = ";",stringsAsFactors = FALSE)
shinyApp(
ui = dashboardPage(
dashboardHeader(title = "ciliogenics"),
dashboardSidebar(sidebar <- dashboardSidebar(
sidebarMenu(id = "SEARCH",
menuItem("SEARCH", tabName = "SEARCH"),
menuItem("Clinical Signs and Symptoms", tabName = "Clinical Signs and Symptoms"),
menuItem("Diseases", tabName = "Diseases"),
menuItem("Genes", tabName = "Genes"),
menuItem("Classifications and schemas", tabName = "Classification and schemas"),
menuItem("HELP", tabName = "HELP"),
menuItem("Related papers", tabName = "Related papers"),
menuItem("FAQs", tabName = "FAQs")
)
)),
dashboardBody(tabItems(tabItem(tabName = "SEARCH" ,
fluidRow(column(width=6,box(DT::dataTableOutput('myTable'), width=NULL)),
column(width=6,box(textOutput("myText"), width=NULL))))))
),
server = function(input, output, session){
mytbl <- BB
output$myTable <- DT::renderDataTable({DT::datatable(mytbl,
rownames=FALSE)})
output$myText <- renderText({ "The value entered in the seach box should appear here!" })
}
)
解决方案
您可以编写自己的搜索功能。使用mtcars
数据集 -
library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(DT)
shinyApp(
ui = dashboardPage(
dashboardHeader(title = "ciliogenics"),
dashboardSidebar(sidebar <- dashboardSidebar(
sidebarMenu(id = "SEARCH",
menuItem("SEARCH", tabName = "SEARCH"),
menuItem("Clinical Signs and Symptoms", tabName = "Clinical Signs and Symptoms"),
menuItem("Diseases", tabName = "Diseases"),
menuItem("Genes", tabName = "Genes"),
menuItem("Classifications and schemas", tabName = "Classification and schemas"),
menuItem("HELP", tabName = "HELP"),
menuItem("Related papers", tabName = "Related papers"),
menuItem("FAQs", tabName = "FAQs")
)
)),
dashboardBody(tabItems(tabItem(tabName = "SEARCH" ,
fluidRow(column(width=6,box(DT::dataTableOutput('myTable'), width=NULL)),
column(width=6,box(textOutput("myText"), width=NULL))))))
),
server = function(input, output, session){
rv <- reactiveValues(inds = 0, mytbl = mtcars)
output$myTable <- DT::renderDataTable({DT::datatable(rv$mytbl[rv$inds, ],rownames=FALSE, callback = JS(
"table.on( 'search.dt', function () {",
"Shiny.setInputValue( 'search', table.search() );",
"} );"
))})
output$myText <- renderText({paste0("Searching for ...", input$search)})
observeEvent(input$search, {
rv$inds <- which(rowSums(sapply(rv$mytbl, function(x) grepl(input$search, x))) > 0)
})
}
)
推荐阅读
- c# - 按住按钮以继续串行发送变量
- python - 如何跳过输入并生成错误代码?
- emacs - 无法使用 Lualatex 在 AUCTeX 下预览
- node.js - 使用 cli 命令在打包的电子应用程序中使用 node_modules
- javascript - 将表单信息发送到服务器的最佳实践
- java - Vera 代码报告中的加密算法违规
- java - 如何生成 Java PKCS12 存储以连接到常规 SSL 网站?
- windows - 让我保持登录功能如何在 Windows/桌面应用程序中工作
- javascript - 在选择下拉列表中更改时无法调用 javascript 函数
- google-cloud-run - 向 Cloud Run 中的内部方法添加跟踪