r - 在带有按钮的闪亮应用程序中显示预定义的图
问题描述
我正在尝试制作一个带有单选按钮的小型 Shiny 应用程序,用于选择一个图(在代码中预定义)并显示它。这就是我所拥有的:
# The plots called "Plot1" etc. are predefined in the environment.
Interface <- {
fluidPage(
sidebarPanel(
radioButtons(inputId = "Question",
label = "Plots",
choices = c("A" = "Plot1",
"B" = "Plot2",
"C" = "Plot3"),
selected = "Plot1")),
mainPanel(uiOutput('ui_plot'))
)
}
Server <- function(input, output){
output$barplot <- renderPlotly({
if (input == "A") return(Plot1)
else if (input == "B") return(Plot2)
else if (input == "C") return(Plot3)
})
}
shinyApp(ui = Interface, server = Server)
但这不起作用。我试过替换return()
,renderPlot()
但它没有改变任何东西。
很抱歉,这可能是一个非常愚蠢的问题/错误,但这是我第一次使用 Shiny!感谢大家!
解决方案
您的代码中有几个错误。
在界面中:替换uiOutput('ui_plot')
为plotlyOutput("barplot")
。
在服务器中:
替换
input
为input$Questions
替换
"A"
为"Plot1"
等
那是:
output$barplot <- renderPlotly({
if (input$Questions == "Plot1") return(Plot1)
else if (input$Questions == "Plot2") return(Plot2)
else if (input$Questions == "Plot3") return(Plot3)
})
推荐阅读
- java - csvWriter 在 Java 中的单元格中写入长数字
- reactjs - 单元测试 - 使用 Jest & Enzyme 在 React 中链接
- excel - 将多个工作表中的列合并到另一个工作表上的单个列中
- r - 未找到 is.dataframe(data) 对象中的疏通错误
- java - 为什么Double会在小数点后获得额外的数字?
- c# - 在 Rider 中调试 unity android,找不到 Android Player 进程
- javascript - 带有大量噪点的平面阴影三防材质渲染
- mysql - 使用联合编写此查询的另一种方法是什么?
- vagrant - Windows主机上的VMware同步文件夹速度?
- node.js - 招摇“响应验证失败:值应为数组/对象但不是”