简体   繁体   中英

How do you make a search bar to query a formattable table in a Shiny Dashboard

I am having trouble seeing how to use the esquisse package to support the searchbar feature here. I want to be able to filter through a name. For example, if someone were to search setosa, it would return a formatted table that is subsetted. I was looking through the esquisse package, but I wasn't sure how to integrate it into a Shiny Dashboard. it seems like I need to change the output in the server. 带有虚拟数据的仪表板示例

library(tidyverse)
library(janitor)
library(shinydashboard)
library(shiny)
library(formattable)
library(golem)
library(esquisse)



#Loading Dummy Data 
data(iris)
summary(iris)
df <- iris
formattable(df)



ui <- dashboardPage(
  dashboardHeader(title = "Title"),
  dashboardSidebar(sidebarSearchForm(label = "Name", "searchText", "searchButton")),
  dashboardBody(formattableOutput("table"))
)

server <- function(input, output) {

  output$table <- renderFormattable({  formattable(df, align = c("l",rep("r", ncol(df))), list(
    `Indicator Name` = formatter("span", style = ~ style(color = "grey",font.weight = "bold")), 
    area(col = 2:length(df)) ~ color_tile("#DeF7E9", "#71CA97")))})


  }

shinyApp(ui = ui, server = server)

You can use as.datatable as shown below:

as.datatable(
      formattable(blah blah blah)
)

Also if you want to use datatable options and filters etc. use them as shown below:

as.datatable(
  formattable(blah blah blah)
,filter = 'top', rownames = FALSE)

See below for example: to see where to place your datatable editing features and where to place your formattable editing features:

as.datatable(
  formattable(mydata, 
            align = c("l",rep("r", NCOL(mydata) - 1)),
            list(`column_1` = formatter("span", style = ~ style(color = "grey", font.weight = "bold")), 
     `column_2` = formatter("span", style = ~ style(color = "blue")),
     `column_3` = formatter("span", style = ~ style(color = "black")),
     `column_4` = formatter("span", style = ~ style(color = "red", font.weight = 
                  "bold"))
     ))
,filter = 'top', rownames = FALSE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM