R rCharts Morris-rChart未展出(在特殊情况下)
我在我的R rCharts Morris-rChart未展出(在特殊情况下),r,plot,shiny,rcharts,morris.js,R,Plot,Shiny,Rcharts,Morris.js,我在我的shinny应用程序中使用rCharts时遇到了一个问题。我动态生成1-3个选项卡面板(取决于用户选择),并在每个面板中呈现一个绘图。绘图可以有两种类型:简单(带图形库)或rCharts(带morris库)。每次用户更改输入时,整个选项卡面板都会在uiOutput组件中呈现。当呈现选项卡面板时,会定义ui输出的类型(plotOutput用于简单打印或showOutput用于rCharts),因此打印没有合适的环境 问题是:简单绘图(带有图形、ggplot2等)工作正常-它们在选项卡面板中
shinny
应用程序中使用rCharts
时遇到了一个问题。我动态生成1-3个选项卡面板
(取决于用户选择),并在每个面板中呈现一个绘图。绘图可以有两种类型:简单(带图形库)或rCharts(带morris库)。每次用户更改输入时,整个选项卡面板
都会在uiOutput
组件中呈现。当呈现选项卡面板
时,会定义ui输出的类型(plotOutput
用于简单打印或showOutput
用于rCharts),因此打印没有合适的环境
问题是:简单绘图(带有图形、ggplot2等)工作正常-它们在选项卡面板中正确显示。但是,当我使用应用程序并显示2或3个rCharts时,一个图表几乎根本不显示(请参见下图)。当然,这样的问题不会出现在简单的绘图中
我尝试将输出大小固定,大小灵活,但问题仍然存在。我有R的变量和库,如下所示:
> R.Version()$version.string
[1] "R version 3.0.1 (2013-05-16)"
> packageVersion("Shiny")
[1] ‘0.7.0’
> packageVersion("rCharts")
[1] ‘0.3.51’
非常感谢您的建议
r开始工作正常:
rCharts无法显示正常:
编辑:我的代码如下:
UI
library(shiny)
library(Epi)
shinyUI(pageWithSidebar(
headerPanel("Header"),
sidebarPanel(
checkboxInput(inputId = "checkboxInputx", label = "function: x", value = TRUE),
checkboxInput(inputId = "checkboxInputxpower2", label = "function: x^2", value = FALSE),
checkboxInput(inputId = "checkboxInput2x", label = "function: 2x", value = FALSE),
actionButton("gobutton","GO!")
),
mainPanel(
radioButtons("plottypechoice", "Choose plot type", c("simple", "rCharts")),
uiOutput("plotpanelcontent")
)
))
服务器
library(shiny)
library(rCharts)
library(Epi)
library(reshape2)
# build data frame
x <- 1:100
df <- data.frame(x, x^2, 2*x)
names(df) <- c("x", "xpower2", "2productx")
shinyServer(function(input, output) {
# generate tabsetPanel with tabPlots with plot of selected type
output$plotpanelcontent <- renderUI({
if(input$gobutton != 0){
# collect tab names
tab.names <- vector()
if(input$checkboxInputx) tab.names <- c(tab.names, "x")
if(input$checkboxInputxpower2) tab.names <- c(tab.names, "xpower2")
if(input$checkboxInput2x) tab.names <- c(tab.names, "2productx")
print(tab.names)
# render tabs
tabs <- lapply(tab.names, function(tab.name){
# define tabPanel content depending on plot type selection
if(input$plottypechoice == "simple")
tab <- tabPanel(tab.name, plotOutput(paste0("simpleplot", tab.name)))
else
tab <- tabPanel(tab.name, showOutput(paste0("rchartplot", tab.name), "morris"))
return(tab)
})
return(do.call(tabsetPanel, tabs))
}
})
# Render simple plots
output$simpleplotx <- renderPlot({
print(plot(df[,1], df[,1]))
plot(df[,1], df[,1])
})
output$simpleplotxpower2 <- renderPlot({
print(plot(df[,1], df[,2]))
plot(df[,1], df[,2])
})
output$simpleplot2productx <- renderPlot({
print(plot(df[,1], df[,3]))
plot(df[,1], df[,3])
})
# Render rCharts
output$rchartplotx <- renderChart({
plot <- mPlot(x="x", y="x", type = "Line", data = df)
plot$set(dom = "rchartplotx")
return(plot)
})
output$rchartplotxpower2 <- renderChart({
plot <- mPlot(x="x", y="xpower2", type = "Line", data = df)
plot$set(dom = "rchartplotxpower2")
return(plot)
})
output$rchartplot2productx <- renderChart({
plot <- mPlot(x="x", y="2productx", type = "Line", data = df)
plot$set(dom = "rchartplot2productx")
return(plot)
})
})
并在重新启动R会话后运行代码。不幸的是,现在情节似乎表现得更加离奇。按以下顺序执行操作后:
设置:“功能:x”,“rCharts”,开始[确定]
添加:“函数:x^2”[请参阅下面帖子中的“不确定”图片]
添加:“功能:2x”[请参阅下文所附的“not_ok_2”图片]
我收到的绘图可视化如下:
正常
“不正常”图像
“不正常”图像
显示您的代码,以便我们可以看到它与工作示例(如提供的代码)之间的差异!谢谢你的关注,GSee。试着更新一下。您的代码在使用相同版本的R时适用于我,但在使用Shining 0.8.0(我还安装了旧版本的rCharts)GSee时,我遵循了您的建议(获得packageVersion(“Shining”)[1]“0.8.0”
),问题没有得到解决。正如我提到的,它不是每次都会发生,而是在某些情况下(在一些用户输入和操作组合之后)。例如,请尝试按以下顺序执行操作:1。设置:“功能:x”,绘图:“简单”[OK]2。将绘图更改为:“rCharts”[OK]3。添加功能:“功能:2x”[请参见两个选项卡面板均显示正常]4。添加函数:“函数:x^2”[请参阅:2个选项卡面板(“x”,“xpower2”)正常,但选项卡面板“2productx”未正确显示!!!]正常。这正是我得到的,所以至少我们现在在同一页:)好的事情是,情节显示出来了。我将调查x-y范围内奇怪现象背后的原因。
> packageVersion("Shiny")
[1] ‘0.8.0’
> packageVersion("rCharts")
[1] ‘0.3.53’