我编写了一个小应用程序,您可以在其中看到一个单选按钮,您可以使用它在绘图图表和渲染表格之间切换。有用。之后我阅读了有关模块的 Shiny 文档并最终得到了这个应用程序:
我的应用程序R
library(shiny)
ui <- fluidPage(
fluidRow(
column(6,
chartTableSwitchUI("firstUniqueID")
)
)
)
server <- function(input, output) {
callModule(chartTableSwitch, "firstUniqueID")
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
我编写了一个 globar.R ,如下所示:
library(shiny)
library(plotly)
#define a simple dataframe for module example
X <- c("a", "b", "c")
Y <- c(1,2,3)
df <- data.frame(X,Y)
#UI function for first module
chartTableSwitchUI <- function(id){
ns <- NS(id)
tagList(
radioButtons("rb1", "View", choices = c(ns("Chart"), ns("Table")),
selected = "Chart", inline = TRUE),
conditionalPanel(
condition = "input.rb1 == …Run Code Online (Sandbox Code Playgroud)